0

In all the examples I've reviewed of Grails command objects, the authors use new action names in their controllers (eg, "login", "register") rather than "create" or "save."

Does the use of command objects for processing form data preclude the use of "create" and "save" as function names in the controller? If yes, is it because these actions presume the use of domain objects rather than command objects?

(Context: trying to get a form to repopulate after a CO fails validation has been pure agony.)

ScottyDont
  • 1,207
  • 1
  • 9
  • 17

1 Answers1

1

No that is not prohibited by Grails at all and is fairly common. There is nothing stopping you from using Command objects to back your forms and base your saving/creating/etc. from and using controller names such as create and save.

Joshua Moore
  • 24,706
  • 6
  • 50
  • 73
  • So what's the pattern for passing a command object back and forth from create and save? When I try to pass back an instantiated CO from the save action to the create action, I get all kinds of error, most notably "[CommandObject instance name] has no property: action. – ScottyDont Mar 17 '16 at 20:39
  • That's a different question. However, it involves rendering your model with the instance of the command object. Take a look at the documentation on `render` and understand how the model is provided from your controller to your GSPs. It's not uncommon to see def save(MyCommandObject obj) { ... render(view: 'someView', model: [instance: obj]) ... then ${obj.name} in your GSPs. – Joshua Moore Mar 17 '16 at 20:42