Grails分页无法维持会话

时间:2014-08-21 05:19:13

标签: grails pagination

我有一个包含数据库内容和搜索按钮的表格。它有分页。我的搜索字段名称为filterStatus。我需要把话题放在分页上。我最初有15页分页,当我应用搜索时,它变为5页。问题是在搜索后点击paginate它不是维护会话并返回15页。代码如下:

<g:form  contoller="adminMaster" onsubmit="return validateFields()">
           <g:hiddenField name="mysearch" value="mysearch"/>
                    <div class="span3">
                        <select class="top5" name="filterStatus" id="filterStatusId">
                            <option value="0" selected>Status</option>
                            <option value="true">Active</option>
                            <option value="false">Inactive</option>
                        </select>
                    </div>
                    <div class="span2">
                        <div class="order_id_cancel top5">
<g:actionSubmit  class="btn btn-danger" value="Search" name="searchButton" id="searchButtonId" action="category"/>
</g:form>

....... <g:paginate next="&raquo;" prev="&laquo;" controller="adminMaster" action="category" total="${dataCount}" />

我在那里添加了一个隐藏的文件来维护会话。 <g:hiddenField name="mysearch" value="mysearch"/>

我的控制器逻辑如下:

def category = {
if(params.mysearch == null){
            println "inside ifffffffff......"
            params.filterStatus = session.formSession == null ? null : session.formSession.filterStatus
            params.mysearch = session.formSession == null ? null : session.formSession.mysearch
        }
        else{
            println "else..........."
            session.formSession = params

            params.max = params.mysearch != null ? null : params.max
            params.offset = params.mysearch != null ? null : params.offset
        }  

}

请帮帮我。它是在grails上。

1 个答案:

答案 0 :(得分:1)

在控制器中:

def index(Integer max) {
    params.max = Math.min(max ?: 10, 100)
 if(params.mysearch){
     List<DomainName> domainInstanceList = DomainName.list(params)

  } else {
/*Do somthing to search your list. It would be better if you are using createCriteria*/
 }
Long totalCount = domainInstanceList.totalCount
render view: 'viewName', model:[clientInstanceList:clientInstanceList,domainInstanceCount: totalCount]
}

在gsp页面中:

/*Display your data here*/

<div class="custom-pagination">
    <g:paginate total="${domainInstanceCount ?: 0}" params="${params}"/>
</div>

希望它会对你有所帮助。