> 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?
It is a hack :-) And a reasonable one!
I think binding of multi-selectable references should behave just like the
binding of singly selectable reference.
I also think it is doable, just not implemented yet. For example:
class Query {
List repositories
static hasMany = [repositories:Repository]
}
binder has all the information it needs to bind from a list of rep ids
to the list of repository objects to fetch from DB. That is how the
simple reference bindings (select with one item selectable) are done.
Alex.
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email