|
I am generating this select list within a for loop in the gsp
<g:select from="${item.options}" id="headerItemOptions_${item.id}" name="headerItemOptions_${item.id}" multiple="true"/> For loop: <g:each var="${item}" in="${review.headerItems}"> But I am not getting the select list in my params in the controller. What am I doing wrong? Please note I have several other textboxes, etc on the page which I am able to access in the controller. I can even access the select list if I remove the multiple="true" option. However, I need a multi-select list and I want to be able to access that in the controller. How do I do that? I would appreciate any help. Cheers Bhushan |
|
This post has NOT been accepted by the mailing list yet.
Hi!
in controller checking on flatten list
def xxxxxx = [.headerItems.toList()] ? [.headerItems].flatten() : null
def xxxxxx.collect {
}
|
|
In reply to this post by bhushan154
It's tough to say from your example.
You should be seeing *something* in your controller when you retrieve the param with something like... params['headerItemOptions_' + itemIdYouUsedToGenerateSelectElements] Dealing with submission from select-multiple can be tricky, if no choice is selected, you'll get a null, if one choice is selected you'll get a single string, if more than one is selected, you'll get a List of Strings. You shield yourself from all that by using this to retrieve the submitted values... params.list('headerItemOptions_' + itemIdYouUsedToGenerateSelectElements) ... that will ensure you always get a list back (even if it's just an empty one). Keep in mind that will be a list of *strings* and your item.id's are probably Longs. So if you're going to be doing any comparisons of the form-submitted Id's to real domain-object Id's, I'd suggest retrieving values like this... params.list('headerItemOptions_' + itemIdYouUsedToGenerateSelectElements)*.toLong() ... that will give you a list of Longs perfect for doing things like "contains" comparisons with domain object ids. Again, now sure why you're seeing no submitted data. I suggest looking carefully at the HTML being generated and seeing if it's what you want (or posting the generated HTML back here and some of your Controller's retrieval code so that we can make out more of the situation). - Gary On Jun 12, 2012, at 12:31 AM, bhushan154 wrote: > I am generating this select list within a for loop in the gsp > > <g:select from="${item.options}" > id="headerItemOptions_${item.id}" > name="headerItemOptions_${item.id}" > multiple="true"/> > > For loop: > <g:each var="${item}" in="${review.headerItems}"> > > But I am not getting the select list in my params in the controller. > > What am I doing wrong? Please note I have several other textboxes, etc on > the page which I am able to access in the controller. I can even access the > select list if I remove the multiple="true" option. However, I need a > multi-select list and I want to be able to access that in the controller. > How do I do that? > > I would appreciate any help. > > Cheers > Bhushan > > > > -- > View this message in context: http://grails.1312388.n4.nabble.com/Multi-select-list-in-params-tp4629951.html > Sent from the Grails - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
On 14/06/2012 02:16, Gary Affonso wrote:
> It's tough to say from your example. > > You should be seeing *something* in your controller when you retrieve the param with something like... > > params['headerItemOptions_' + itemIdYouUsedToGenerateSelectElements] > > Dealing with submission from select-multiple can be tricky, if no choice is selected, you'll get a null, if one choice is selected you'll get a single string, if more than one is selected, you'll get a List of Strings. You shield yourself from all that by using this to retrieve the submitted values... > > params.list('headerItemOptions_' + itemIdYouUsedToGenerateSelectElements) As an aside, note that in this case you do need to use the + operator rather than gstrings: params["headerItemOptions_${itemId}"] and params.list("headerItemOptions_${itemId}") will more than likely *not* work, because the map keys are of type String, not GString. Ian -- Ian Roberts | Department of Computer Science [hidden email] | University of Sheffield, UK --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
