开发者

grails, add only existing params from current url to pagination

开发者 https://www.devze.com 2023-03-30 23:06 出处:网络
guys! I`d like to make \'clever pagination\'. For example, if i already have params.category=Auto - i want it to be added to my params.

guys! I`d like to make 'clever pagination'. For example, if i already have params.category=Auto - i want it to be added to my params. Of course, i can do smth like this :

<g:paginate total="${total}" 开发者_开发百科max="10" maxsteps="5" params="[category: params.category,subcategory: params.subcategory]"/>

But if current params.subcategory is null - it will also be added to url ( ?subcategory=&category=Auto) . I don`t want to have 'subcategory=' in my params in such a case! Also I can do it with string concatenations to create new url - but maybe grails have some cheats/mechanism to create new url without string concatenations?

Cheers, Dmitry.


There aren't any great solutions I can think of. You could try:

params="${[category: params.category,subcategory: params.subcategory].findAll {it.value} }"

Alternatively, provide your own custom tag that strips out null param values before delegating to the paginate tag.

0

精彩评论

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