I have been updating some of my controllers to use command objects and started down the road of making a PaginateCommand for other command objects to extend.
class PaginateCommand {
String sort
String order
Integer max
Integer maxsteps
Integer offset
Integer total
}
Sub command class
@Validateable
class MyOtherCommand extends PaginateCommand {
...
}
Controller
class SomeController {
def someService
def index(MyOtherCommand cmd) {
someService.loadSomeList(cmd)
return [cmd: cmd]
}
}
This all works great and my controllers are now nice and simple. The problem now is the paginate tag is giving me issues. This is what I originally assumed would work:
<g:paginate total="${cmd.total}" params="${cmd.properties}" />
However the paginate tag only looks at the params attached to the request for most values and not the ones passed in on the params attribute. I must manually pass these variables in as attributes like total is above.
All of the pagination variables seem to get removed from the request params when they are bound to the command object (I assume). I would like to keep these variables in the command object so I don't have to pass the request params to my services. Having the controller repopulate the params before rendering also seems counter productive.
Am I stuck having to populate every argument in the paginate tag or is there another way I am missing?
<g:paginate total="${cmd.total}" offset="${cmd.offset}" max="${cmd.max}".... />
P.S. I am using Grails 2.3.6