Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy/Grails Contains with Lowercase

I want to check a list contains a specific string .

before checking all entries in list as well as sting should be in. lowercase

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 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: []
like image 995
maaz Avatar asked Jan 09 '13 08:01

maaz


1 Answers

I agree with aiolos: use constraints or try to find instance by name ignore case. But to fix this your way try *. (spread operator):

venueNameLists*.toLowerCase().contains(venueName.toLowerCase()) 
like image 167
Mr. Cat Avatar answered Sep 21 '22 11:09

Mr. Cat