Grails Command Objects and Pagination -
i have been updating of controllers use command objects , started down road of making paginatecommand other command objects 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 works great , controllers nice , simple. problem paginate tag giving me issues. assumed work:
<g:paginate total="${cmd.total}" params="${cmd.properties}" />
however paginate tag looks @ params attached request values , not ones passed in on params attribute. must manually pass these variables in attributes total above.
all of pagination variables seem removed request params when bound command object (i assume). keep these variables in command object don't have pass request params services. having controller repopulate params before rendering seems counter productive.
am stuck having populate every argument in paginate tag or there way missing?
<g:paginate total="${cmd.total}" offset="${cmd.offset}" max="${cmd.max}".... />
p.s. using grails 2.3.6
thanks doelleri. tag simple enough implement ended using paginate tag is. typically 3 attributes needed (total, max, , offset), figured wasn't big enough issue introduce new custom tag. params attribute on paginate tag designed pass request parameters maintain state of filters/sorting/etc, suppose makes sense grails not use populate other attributes in tag.
i did end adjusting paginate command class because subclass had collections , other properties needlessly cluttered request parameters. ended doing.
abstract class paginatecommand { string sort string order integer max integer maxsteps integer offset integer total // properties needed maintain pagination state abstract map getfilterparams(); public map getpaginateparams() { return [sort:sort, order:order] << filterparams } }
sub command
@validateable class myothercommand extends paginatecommand { string filter1 string filter2 list data public myothercommand() { max = 50 sort = "id" order = "desc" } map getfilterparams() { [filter1: filter1, filter2: filter2] } ... }
controller
def index(myothercommand cmd) { someservice.loaddata(cmd) return [cmd: cmd] }
and in gsp
<g:paginate total="${cmd.total}" max="${cmd.max}" maxsteps="${cmd.maxsteps}" offset="${cmd.offset}" params="${cmd.paginateparams}" />
Comments
Post a Comment