开发者

Grails controller, Command Object explotion

In Grails controller actions, for validations, We use command objects. The problem is the number of CommandObject classes have exploded.

 def publish = { PublishCommand command ->
        if (command.hasErrors()) {
            return redirect(action: 'errors',params:params)
        }
        //rest of the code
  }
 ......

Class PublishCommand {
   long personId
   String name
   static constraints = {
        personId(nullable: false, blank: false)
        name(nullable: false, blank: false)

   }
}

PublishCommand Class exists only开发者_如何学Go for this databinding & validation purpose. Number of such classes have exploded, 1 created for each of the action of the application. Question is, Is there a way I can have this PublishCommand as innerClass? Or other ways where I don't have to create so many classes?


It's a pretty common practice to place the command object classes within the same .groovy file as the controller (after the controller class). This will help cut down on the number of files you have to manage. Otherwise, you are following best practices (from what you have described).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜