为什么在使用延迟加载对任何字段 Prime Faces 数据 table 进行排序后过滤器变为空?

Why filters are becoming null after sorting any field Prime Faces data table with lazy loading?

我搜索了很多问题,尝试了很多东西。 下面我有一些片段步骤来产生问题。 首先对任何列应用过滤器值,然后对 table 接口中存在的任何列过滤器值应用排序,但在加载方法 filters.isEmpty() 为真。

                         <p:dataTable id="tbl" value="#{service}"
                                         selection="#{bean.selectedObj}" 
                                         filteredValue="#{bean.listFilteredObj}" 
                                         var="obj"
                                         multiViewState="true"  
                                         rows="50"
                                         widgetVar="tbl1" filterEvent="keyup"
                                         draggableColumns="true"
                                         emptyMessage="No Obj found"
                                         paginator="true"  
                                         paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                         rowsPerPageTemplate="50,100" 
                                         paginatorAlwaysVisible="true"
                                         rowKey="#{opp.oppId}"
                                         tableStyle="table-layout:auto;" resizableColumns="true" resizeMode="expand"
                                         rowSelectMode="add"
                                         lazy="true"
                                         rowIndexVar="index"
                                         class="fixed-scrollbar"
                                         style="margin: -10px!important; height: 85vh">
                                <p:ajax event="rowSelectCheckbox" listener="#{service.onRowSelectCheckbox}" update=":dtForm:tbl:btnClose :dtForm:tbl:btnUpdate" />
                                <p:ajax event="rowUnselectCheckbox" listener="#{service.onRowUnselectCheckbox}" update=":dtForm:tbl:btnClose :dtForm:tbl:btnUpdate" />
                                <p:ajax event="toggleSelect" listener="#{service.onToggleSelect}"  update=":dtForm:tbl:btnClose :dtForm:tbl:btnUpdate"  />
                                <p:ajax event="page" listener="#{objFilter.onPageChange}" /> 

                                <p:ajax event="page" listener="#{service.onPagination}" update=":dtForm:tbl"/>  
                                <p:ajax event="colReorder" listener="#{service.onColumnReorder}"/>
                               
                                <p:column exportable="false" toggleable="false" selectionMode="multiple" style="width: 10px;text-align: center;"/>

                                <p:column headerText="Id"  style="display: none" exportable="true"  visible="false" toggleable="false">
                                    <p:outputLabel value="#{obj.Id}"  />
                                </p:column>
                                <c:forEach var="column" items="#{service.listOppColumns}">
                                   
                                    <p:column headerText="#{column.columnHeader}" id="#{column.columnName}"  
                                              visible="#{column.columnVisibleFlag==1}"  
                                              filterMatchMode="#{column.columnFilterMatchMode}" 
                                              filterBy="#{column.columnName=='insDate' || column.columnName=='updDate' ? globalParams.formatDateTime(obj[column.columnName], 'dt') : column.columnName=='oppFollowUp' ? globalParams.formatDateTime(obj[column.columnName], 'da') : opp[column.columnName]}" 
                                              sortBy="#{obj[column.columnName]}" exportable="#{column.columnVisibleFlag==1}"
                                              field="#{column.columnName}">   
                                        <c:choose>
                                           
                                            <c:when test="#{column.columnName=='objFol'}">
                                                <h:link outcome="ObjView.xhtml?id=#{obj.Id}" value="#{globalParams.formatDateTime(opp[column.columnName],'da')}">
                                                    <f:param name="frm" value="#{view.viewId}" />
                                                    <f:param name="moduleId" value="0" />
                                                </h:link>
                                            </c:when>
                                            <c:when test="#{column.columnName=='objDate'}">

                                                <h:link outcome="objView.xhtml?id=#{obj.objId}" value="#{globalParams.formatDateTime(obj[column.columnName],'da')}">
                                                    
                                                    <f:param name="frm" value="#{view.viewId}" />
                                                    <f:param name="moduleId" value="0" />
                                                </h:link>
                                            </c:when>
                                            <c:when test="#{column.columnName=='objPro'}">

                                                <h:link outcome="ObjView.xhtml?id=#{obj.Id}" value="#{globalParams.formatDateTime(opp[column.columnName],'da')}">
                                                    
                                                    <f:param name="frm" value="#{view.viewId}" />
                                                    <f:param name="moduleId" value="0" />
                                                </h:link>
                                            </c:when>
                                            <c:when test="#{column.columnName=='insDate'}">
                                                <h:link outcome="ObjView.xhtml?id=#{obj.Id}" value="#{globalParams.formatDateTime(opp[column.columnName],'dt')}">
                                                    
                                                    <f:param name="frm" value="#{view.viewId}" />
                                                    <f:param name="moduleId" value="0" />
                                                </h:link>
                                            </c:when>
                                            
                                            <c:when test="#{column.columnName=='updDate'}">
                                                <h:link outcome="OpportunityView.xhtml?opid=#{opp.oppId}" value="#{globalParams.formatDateTime(opp[column.columnName],'dt')}">
                                                    <f:param name="frm" value="#{view.viewId}" />
                                                    <f:param name="moduleId" value="0" />
                                                </h:link>
                                            </c:when>
                                            <c:otherwise>
                                                <h:link outcome="ObjView.xhtml?id=#{obj.Id}"    
                                                        value="#{obj[column.columnName]}"  >
                                                    <f:param name="frm" value="#{view.viewId}" />
                                                    <f:param name="moduleId" value="0" />
                                                </h:link>
                                            </c:otherwise>
                                        </c:choose>   
                                    </p:column>
                                </c:forEach> 
                            </p:dataTable>

service.java

...
...
...
 @Override
    public List<ViewObjList> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
        globalFlt = new StringBuilder("");
        StringBuilder order = new StringBuilder("");
        StringBuilder tableFlt;
        tableFlt = tableFlt(filters);
        System.out.println("\nfilter is null = "+filters.isEmpty());
        if (sortField != null) {
            if (!sortField.trim().equals("")) {
                order.append(sortField);
                if (sortOrder.equals(SortOrder.DESCENDING)) {
                    order.append(" DESC");
                }
            }
        } else {
            order.append("objFol DESC");
        }

        obj.list = lazyQueryExecute(first, pageSize, globalFlt.toString(), tableFlt.toString(), order.toString());
        obj.listFiltered = obj.list;
        return obj.listFiltered;
    }

    private List<ViewOppList> lazyQueryExecute(int first, int pageSize, String globalFlt, String tableFlt, String order) {
        StringBuilder queryList = new StringBuilder("from ViewOppList ");
       
        String and = "and (";
        queryList.append("where (").append(DepList()).append(") ");

        if (!tableFlt.trim().equals("")) {
            queryList.append(and).append(tableFlt).append(") ");
        }

        if (!globalFlt.trim().equals("")) {
            queryList.append(and).append(globalFlt).append(") ");
        }

        String rowCount = "select count(*) " + queryList;
        long rowC = (long) dao.qryObject(rowCount);
        setRowCount((int) rowC);

        if (!order.trim().equals("")) {
            queryList.append(" order by ").append(order);
        }

        showTotal.append(queryList);
        opp.setOppSubTotal((BigDecimal) dao.qryObject(showTotal.toString()));
        System.out.println("query = " + queryList);
        return dao.qryListMaxLim(queryList.toString(), Dao.query.HQL, first, pageSize);
    }

    @Override
    public ViewObjList getRowData(String rowKey) {
        if (obj.listFiltered != null) {
            for (ViewObjList objo : obj.listFiltered) {
                if (objo.getId() == Integer.parseInt(rowKey)) {
                    return objo;
                }
            }
        }

        return null;
    }
    @Override
    public String getRowKey(ViewObjList obj) {
        return String.valueOf(obj.getId());
    }

private StringBuilder tableFlt(Map<String, Object> filters) {
        StringBuilder tableFlt = new StringBuilder("");
        if (!filters.isEmpty()) {
            for (Map.Entry<String, Object> entry : filters.entrySet()) {
                String field = entry.getKey();
                String value = (String) entry.getValue();
                if (!field.trim().equals("") && !value.trim().equals("")) {
                    if (field.equalsIgnoreCase("globalFilter")) {
                        globalFlt.append(globalSearch(value));
                    } else {
                        // colmn LIKE '%value% and column1 Like '%value1%'
                        tableFlt.append(field).append(" LIKE '%").append(value).append("%' and ");
                    }
                    System.out.println("\n\n\n field = " + field + ": vlue = " + value);
                }
            }
            if (tableFlt.length() > 3) {
                tableFlt.delete(tableFlt.length() - 4, tableFlt.length());
            }
        }
        return tableFlt;
    }

我只显示了重现问题所需的小片段。在此代码中,我们首先应用将显示正确查询列表的过滤器 (filters.isEmpty() = false),但是当在记录 filters.isEmpty() = true 后从 table at load 方法应用排序时数据 table 中甚至存在过滤值。 我正在使用 prime faces 版本 6.2 和 jsf 2.2,并使用 hql 查询从 MySQL data table

获取数据

任何帮助将不胜感激 提前致谢。

在这个问题上花了几天时间后,我发现有一些嵌套形式导致了这个问题,上面的代码没问题,我也保留了这个问题,这样其他人就不会遇到此类问题。 JSF 不允许嵌套表单需要显示该错误。