« Return to Thread: g:select with multiple preselected values

Re: g:select with multiple preselected values

by hdockter :: Rate this Message:

Reply to Author | View in Thread

Hi Alex,

I use the binding in the following way:

If you look at the example in my original mail, I use 'repositoryKeys' as the value for the name property of the g:select element. After the form is submitted, the multiple selected values are automatically bound to the corresponding object. Grails is doing a good job here. In this example I'm actually interested in binding the repositories to my object, not the repositoryKeys. They are just a helper. Here is the class associated with the view.

class Query {

  List repositories
 
  void setRepositoryKeys(List keys) {
          repositories = keys.collect{Repository.REPOSITORIES[it]}
  }
 
  List getRepositoryKeys() {
          repositories.collect{it.key}
  }
}

I create getters and setters for repositoryKeys, although there is no field repository keys. Grails calls now automatically the setter, and passes the list of selected values to the setter. The setter maps the keys to my corresponding groovy objects. The other way round would work the same, if there were a way I could pass multiple preselected values to the g:select element. Then I could say:

<g:select ... value="${query?.repositoryKeys}"/>

I can't see how Grails can make this more convenient, except of course offering multiple preselection. What do you think?

- Hans

Alex Shneyderman wrote:
I am afraid not. There is also a backend problem as mutiply selected
values have no way to bind. I guess, select tag needs a bit of a
makeup in this regard.

On 4/25/07, hdockter <mail@dockter.biz> wrote:
>
> I'm using the g:select element with multiple selections enabled:
>
> <g:select multiple="multiple" name='repositoryKeys'
> from="${Repository.list()}" optionKey='key' optionValue='name'>
> </g:select>
>
> This works fine. The problem I have, is with setting more than one
> preselected value. The value argument of the g:select element handles only a
> single string, no lists.
>
> Is there a any workaround for this?
>
> I couldn't find anything related to this on the issue roadmap. Multiple
> preselection looks like a major use case to me.

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

 « Return to Thread: g:select with multiple preselected values