|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
g:select with multiple preselected valuesI'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. - Hans |
|
|
Re: g:select with multiple preselected valuesI 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@...> 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 |
|
|
Re: g:select with multiple preselected valuesHi 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
|
|
|
Re: g:select with multiple preselected values> 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 |
|
|
Re: g:select with multiple preselected valuesHi Alex,
Two things. I have forgotten to mention, that Query and Repository are command objects, introduced with 0.5. So there is no defined key like id for those classes. Thanks for pointing to the automagic reference binding of domain objects. I haven't known this mechanism yet. I'm wondering if somehow grails can support reference binding for command objects, beyond the mechanisms I use in my hack. The current reference binding is part of the domain class processing. The simple change of the g:select element dealing with multiple preselections, would have its value independent of improving reference binding. I have added this feature to the g:select tag on my machine. There is now a property values, which accepts a list. Either value or values can bet set (or none). I gonna open a Jira issue and attach the patch. - Hans |
| Free embeddable forum powered by Nabble | Forum Help |