porno porno rokettube
Results 1 to 3 of 3

Thread: Add constraints to the elemets of List

  1. #1
    Junior Member
    Join Date
    Feb 2015
    Posts
    5

    Add constraints to the elemets of List

    Is there are any possible way to add constraints to the elements of List? For example I have a command which accept List and I want add constraints on this elements, for example on size.

    Code:
    class SongCommand {
    
        String title
        List<String> couplet
        List<String> chorus
        Boolean isChorus
        Boolean isChorusRepeat
    
        static constraints = {
            title(blank: false, maxSize: 6)
            isChorus(blank: true)
        }
    
    }
    How to do that?

    Thank you.

  2. #2
    Junior Member
    Join Date
    Feb 2015
    Posts
    5
    I have the solution
    Code:
    static constraints = {
      couplet(validator: { val ->
        boolean isValid = true 
        val.each {
          if (it.size() < 3) isValid = false
        } 
    
        return isValid
      })
    }
    It's not final, but as example. Better return error code message, not true/false.

  3. #3
    Administrator dave's Avatar
    Join Date
    Mar 2010
    Location
    West Yorkshire, UK - Valencia Spain
    Posts
    110
    Thanks for posting your solution.
    Connect with me on twitter : @davebrown1975 http://twitter.com/davebrown1975

    Web & Mobile Development by Tucanoo Solutions Ltd

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Forum Design by Tucanoo Solutions Ltd Grails Development Specialists.