Details
-
Type:
Sub-task
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.2-RC2
-
Fix Version/s: 2.3-M1
-
Component/s: Controllers
-
Labels:None
Description
It's currently not possible to bind to a collection of domain objects on a command object...
class SomeCommand {
List <User> users
}
It also appears not to be possible to bind to a collection of "primitive" types.
-
Hide
- binding.zip
- 06/Mar/12 4:55 PM
- 125 kB
- Bobby Warner
-
- binding/.classpath 0.7 kB
- binding/.DS_Store 6 kB
- __MACOSX/binding/._.DS_Store 0.1 kB
- binding/.project 0.5 kB
- binding/.../org.codehaus.groovy.eclipse.preferences.prefs 0.1 kB
- binding/application.properties 0.1 kB
- __MACOSX/.../._application.properties 0.2 kB
- binding/.../ApplicationResources.groovy 0.1 kB
- binding/grails-app/conf/BootStrap.groovy 0.1 kB
- binding/grails-app/.../BuildConfig.groovy 1 kB
- __MACOSX/binding/.../._BuildConfig.groovy 0.2 kB
- binding/grails-app/conf/Config.groovy 4 kB
- binding/grails-app/.../DataSource.groovy 1 kB
- binding/grails-app/.../resources.groovy 0.0 kB
- binding/grails-app/.../UrlMappings.groovy 0.2 kB
- binding/grails-app/.../TestController.groovy 0.2 kB
- __MACOSX/binding/.../._TestController.groovy 0.2 kB
- binding/grails-app/.../binding/User.groovy 0.1 kB
- __MACOSX/binding/.../binding/._User.groovy 0.2 kB
- binding/grails-app/.../messages.properties 3 kB
- binding/.../messages_cs_CZ.properties 3 kB
- binding/.../messages_da.properties 3 kB
- binding/.../messages_de.properties 4 kB
- binding/.../messages_es.properties 3 kB
- binding/.../messages_fr.properties 2 kB
- binding/.../messages_it.properties 2 kB
- binding/.../messages_ja.properties 4 kB
- binding/.../messages_nl.properties 3 kB
- binding/.../messages_pt_BR.properties 3 kB
- binding/.../messages_pt_PT.properties 3 kB
Issue Links
- is duplicated by
-
GRAILS-9371
NO LONGER A BUG - Binding List of command child objects repeats themselves
-
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
Bobby,
That doesn't' really test binding a collection of objects, does it? I think we need to verify that if there are request parameters like user[0].firstName, user[1].firstName etc., that a List of User objects is created, initialized and assigned to userCommand.users.
Is that right?
Ah, I see now. Yes, binding collections for command objects does not work. I created and attached an app that will recreate the problem using a Geb functional test ( grails test-app functional: ) Thanks, Bobby
I encountered this issue after upgrading from Grails 1.3.7 to Grails 2.0.1.
In my case I have a command object within a web flow. The command object contains collections (see below). The web flow hangs due to this.
package com.vanguard.ngsacontrol.hudson
import com.vanguard.build.gav.Gav
class JobCreateDetailsCommand implements Serializable {
String kind // CI, Milestone, Both
String svnUrl
String emailList
String hudsonUrl
String hudsonView
// Derived fields
Boolean multiModule
Gav ultimateParentGav
Boolean isVppDescendant
List<String> ciJobNames
List<String> ciJobSuffixes
List<String> ciSvnUrls
String milestoneJobName
String milestoneJobSuffix
Sorry, My comment above was due to a misplaced curly bracket in a gsp which causes the gsp rendering to hang. It has nothing to do with command objects within a web flow.
Here is the culprit (extra } at tend of tag):
Email notifications: <g:textField name="emailList" value="$
{jobCreateDetails?.emailList}" size="60" }/> <br/>
I believe my pull request https://github.com/grails/grails-core/pull/251 may fix this issue. You would, however, need to change your command object to use a lazy list so that the data binding can instantiate a instance of the target list object without knowing it's type.
class SomeCommand {
List <User> users = ListUtils.lazyList([], FactoryUtils.instantiateFactory(User))
}
I (think) this works already in v2.2.0. I have the following command object, and it gets bound just fine:
@Validateable
class RequestedPeersCommand {
Collection<Person> people = [].withDefault { new Person() }
}
I get the impression that they might be holding off on closing some of the data binding tickets until after 2.3 testing since the data binding layer is being completely rewritten in 2.3 IIRC.
We use collection binding in many places with no trouble. One caveat that you have to be careful of is ensuring proper equals() behavior for whatever is in the collection. The binding layer needs to be able to compare default empty versions of domain objects so if you take an approach of defining equals as this.id == that.id, the binding will fail in a non-obvious way.
Since this is binding-related, would it make sense to flag it for v2.3?
Personally, I think that this code is really a workaround to an existing issue
[].withDefault { new Object() }
You cannot use a constraint like "minSize: 1", even with this workaround.
Hopefully the v2.3 fix will address this.
Note that the attached sample application doesn't work because the request parameters are named "user" but the property in the command object is named "users". The bug really exists but even if the bug didn't exist, the test case would have failed. In any case, this should be working now in 2.3.
I am using grails 2.2.0 and still have this issue. passing parameters like resultados[0].property causes a Missing Property exception
Maxwell,
The issue was only recently fixed, after 2.2 was released. Grails 2.3 should not have the problem.
Thanks for the feedback.
I think this might be able to be closed. I can't reproduce with Grails 2.0.1. Here is a controller and test that demonstrates binding a collection to a command object successfully. Thanks, Bobby
package binding class TestController { def index(UserCommand userCommand) { render userCommand.users?.size() } } class UserCommand { List<User> users }