problem with command object missing methods

View: New views
5 Messages — Rating Filter:   Alert me  

problem with command object missing methods

by Steve Tekell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How can this be?
Grails is throwing an error saying my command object class has no hasErrors() method.
The same code works in another application.  Both Grails 1.0.2
Any clues?

Message: No signature of method: BatchUserCommand.hasErrors() is applicable for argument types: () values: {}
Caused by: groovy.lang.MissingMethodException: No signature of method: BatchUserCommand.hasErrors() is applicable for argument types: () values: {}
Class: UserController
At Line: [718]
Code Snippet:
718: if (!batchUserCmd.hasErrors()) {
719: def ok = true

Re: problem with command object missing methods

by linus1412 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Are you passing the command object as a param in the action closure?

I believe doing this will cause Grails to enrich you Command Object with various methods.

Martin

Steve Tekell wrote:
How can this be?
Grails is throwing an error saying my command object class has no hasErrors() method.
The same code works in another application.  Both Grails 1.0.2
Any clues?

Message: No signature of method: BatchUserCommand.hasErrors() is applicable for argument types: () values: {}
Caused by: groovy.lang.MissingMethodException: No signature of method: BatchUserCommand.hasErrors() is applicable for argument types: () values: {}
Class: UserController
At Line: [718]
Code Snippet:
718: if (!batchUserCmd.hasErrors()) {
719: def ok = true

Re: problem with command object missing methods

by Steve Tekell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


linus1412 wrote:
Are you passing the command object as a param in the action closure?
No I am creating an instance within the action.  This was necessary to achieve array binding.  This has worked for me before.  Did 1.0.2 stop decorating command objects unless they were closure params?
I declared it within the controller.

What I am trying to do is handle the creation of multiple Users at once, the number of which varies given a previous step.  I create an input screen with and a list of Users, with fields like userList[0].name.  My BatchUserCommand just has a list called userList to hold a batch of User domain objects.  For the binding to work I have to prepopulate userList with the right number of new Users before I bind.

Is there a better way to do this?
While all the prepopluation was a hassle, the result was I could validate all the new Users with just batchUserCmd.hasErrors().

thx,

Steve

Re: problem with command object missing methods

by Peter Ledbrook-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> No I am creating an instance within the action.  This was necessary to
> achieve array binding.  This has worked for me before.  Did 1.0.2 stop
> decorating command objects unless they were closure params?
> I declared it within the controller.

I believe that at least one action must declare the class as a command
object for the appropriate dynamic properties and methods to be added,
i.e. it has to appear as an action parameter at least once. I would
prefer to see command objects become full blown artefacts, but that
probably won't happen until 1.1 at the earliest.

Cheers,

Peter

--
Software Engineer
G2One, Inc.
http://www.g2one.com/

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

    http://xircles.codehaus.org/manage_email



Re: problem with command object missing methods

by Steve Tekell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> i.e. it has to appear as an action parameter at least once. I would

aha.  I get now why it worked before, it was declared as param
in another action that I wasn't using.

> prefer to see command objects become full blown artefacts, but that
> probably won't happen until 1.1 at the earliest.

Will this mean I won't need to prepopulate a child collection
to the size I need before binding?
And instead could just say MyCmd hasMany children entities?

thx,

Steve