Access to the list of parameters in the controller

Im very new to the grail (1.3.7), so please be patient :-)

I have gsp where I have various checkboxes. The user can click on them and then send his response to the controller. The controller receives this request correctly.

My problem is that in order to work with what the user has selected, I have to check each parameter - to make sure that this checkbox is really checked. This is really cumbersome and doesn’t work very well, because the page displaying the checkboxes is dynamic - so you can also click the checkmarks that you can click. In my controller, I do not know what parameters I need to check.

Is it possible to get a list of all the checkboxes (or better: all checked checkboxes) in my controller? I researched but could not find the answer!

Thanks for answering!:-)

[EDIT]

Thanks,

params.name.each{i-> System.out.println(i); } 

very simple and works :-) It just returns checked

+4
source share
1 answer

It should be passed as an additional request parameter (this is an http restriction). You can add the following field to your form, for example:

 <input type="hidden" name="checkboxes" value="${myCheckboxesNames.join(',')}"/> 

or do the same using JavaScript, as client-side names are dynamic.

By the way, you can also check all request parameters,

 params.each { name, value -> // so something } 

therefore, if you use a special prefix / suffix for these flag names, this will be:

 params.entrySet().findAll { it.key.startsWith(prefix) }.each { println "Checkbox $it.key = $it.value" } 
+10
source

All Articles