简体   繁体   中英

How to retain a search keyword during Grails pagination?

I have a simple Grails application. It has search form with one textfield and one submit button. If the results exceed the total number of 100, then Grails pagination appears and if I click on the second page's link, the call goes to the same controller's method, however, the search keyword is not passed this time (because the pagination is not the part of the search form) and it is not there in 'params'. How to handle this situation?

您可以使用pageScope.variables将所有参数传递给控制器​​,例如

<g:paginate params="${pageScope.variables}" total=.../>

If the name of your input field for search is say q , then you can do something like this:

 <g:paginate controller="user" action="index" total="${total}" q="params.q"/>

This will retain your search keyword on to your paginated pages.

You can send parameters in the paginate tag

<g:paginate next="Forward" prev="Back"
        maxsteps="0" controller="book"
        action="list" total="${bookCount}"
        params="${[q:q, anotherParamether:anotherParamether]}" />

Paginate documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM