2

I have a page that is a report from a database and I'm working on modifying how the filtering works. The intention is to allow the user to select possible values form a list that will be used to filter the resulting report. There are too many values to do this with checkboxes. I'm defining a multiple selection list box with this:

<g:select name="country" from="${countryDataList.KOUNTRY}" value="${params.country}" multiple="true" />

countryDataList is a List<> of objects with a name and a value which I create in the controller. I'm able to get the selected counties and process them without an issue.

But when the page returns from the controller with the filtered report, only the first selection in the list is selected. It doesn't re-select all of the items that the user selected. I am passing the params.country object back from the controller as

country:params.country

I saw some posts about this not working, but they are all from several years ago. Am I missing a vital step?

doelleri
  • 19,232
  • 5
  • 61
  • 65
  • http://stackoverflow.com/questions/8476880/selecting-multiple-values-from-select-tag-grails try this – V H Feb 04 '15 at 18:05
  • Yes, I saw this one. It talks about getting the values from the select in the controller. I'm talking about posting them back into the select when I return to the page. – Joseph Nelson Feb 04 '15 at 18:44

2 Answers2

0

Ahh sorry, I was reading it on the phone initially and missed the point.

So what you want is a way of sending a multiple select box to a confirmation page. If I understand correctly?

Anyways how many objects in the select are we talking massive or a dozen couple of dozen or so ?

What I did was use check boxes and did a confirmation which shows the selection ticked in check boxes.. So this is the confirmation page that loads in https://github.com/vahidhedayati/mailinglist/blob/master/grails-app/views/mailingListEmail/confirmcontact.gsp this page which is where multiple attachments selected from the schedule re-appear... https://github.com/vahidhedayati/mailinglist/blob/master/grails-app/views/mailingListAttachments/_mailerAttachmentsDisplay.gsp.

Please note advice below is all conceptual stuff and there may be easier ways than this

Other than that You could create a taglib call on the confirmation page https://github.com/vahidhedayati/ajaxdependancyselection/blob/master/grails-app/taglib/ajaxdependancyselection/AutoCompleteTagLib.groovy#L55 which takes in your arrayList you could probably convert it to JSON pass it into the javascript that you load in within the taglib (on mine further down it loads this page in) https://github.com/vahidhedayati/ajaxdependancyselection/blob/master/grails-app/views/autoComplete/_selectJs1.gsp#L23

and look to reselect them using javascript... as I say I haven't tested the last bit, the first bit i.e. checkbox works it is/has been in use.

V H
  • 8,382
  • 2
  • 28
  • 48
0

Years later from you I just had the same problem. What I figured out is: it happens when params.country is an array instead of a Collection (i.e. an ArrayList).

A workaround for this if you want to stick to the array type is at the value attribute of the tag doing this: params.country?.findAll().

Douglas Mendes
  • 322
  • 2
  • 12