Groovy / Grails Contains Lower Case

I want to check that the list contains a specific string.

before checking all entries in the list, as well as bite in lower case

I tried like this

def venueName = params.name def venueNameLists = Venue.executeQuery("select name from Venue") if(venueNameLists.toLowerCase().contains(venueName.toLowerCase())){ error = true; log.debug("save :: duplicate name") flash.message = "Venue name already exist"; render(view: "create", model: [venueInstance: new Venue(params)]) return } 

gives an error

  No signature of method: java.util.ArrayList.toLowerCase() is applicable for argument types: () values: []. Stacktrace follows: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.toLowerCase() is applicable for argument types: () values: [] 
+7
source share
3 answers

I agree with aiolos : use restrictions or try to find an instance by name ignore case. But to fix this, try *. ( distribution operator ):

 venueNameLists*.toLowerCase().contains(venueName.toLowerCase()) 
+18
source

If you want to check the duplicate entry before saving the item, use constraints in your domain class. Here you can use a unique constraint or implement your own if you need it is case insensitive .

If you need to check it manually, try the following:

 def venueWithNameFromParams = Venue.findByNameIlike(params.name) // ignore case if(venueWithNameFromParams){ // venueName is in venueNameList } 
+6
source

If you were looking for how to check if a word contains multiple lines, ignoring case, use (? I) in the regular expression of words.

For example, the following will be a positive condition:

 word = "YES" word.matches(/(?i)yes|ok|true/) 
0
source

All Articles