p:datatable中的过滤器不过滤而是不显示任何内容

问题描述 投票:0回答:1

为了尝试处理动态列表和动态html,我在数据表中建立了带有动态列的动态表,所有表都工作正常,并按要求工作,但它不进行过滤,而是不显示任何文本记录输入。 ........................................

@ManagedBean(name="liveRangeService", eager = true)
@ApplicationScoped

public class LiveRangeService implements Serializable {

    ResultSet RS;
    dbConnectionSQLServer db;

    private List< Map<String, ColumnModel> > tableData;
    private Map<String, ColumnModel> selectedData;
    private List< Map<String, ColumnModel> > filteredData;

    public Map<String, ColumnModel> getSelectedData() {
        return selectedData;
    }

    public void setSelectedData(Map<String, ColumnModel> selectedData) {
        this.selectedData = selectedData;
    }
    private List<ColumnModel> tableHeaderNames;
    private String tableColWidths;
    private List< Map<String, ColumnModel> > selectedRow;

    public List<Map<String, ColumnModel>> getTableData() {
        return tableData;
    }
    public List<ColumnModel> getTableHeaderNames() {
        return tableHeaderNames;
    }

    public LiveRangeService() {
    }

    public void LiveRangeServicesss() {
        db = new dbConnectionSQLServer();
        try {
            tableData = new ArrayList< Map<String, ColumnModel> >();
            tableHeaderNames = new ArrayList<ColumnModel>();

            Statement SQL = dbConnectionSQLServer.getCN().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

            RS = SQL.executeQuery("Select * From Coa32 Order BY Title");

            for (int j = 0; j < RS.getMetaData().getColumnCount(); j++) {
                tableHeaderNames.add(new ColumnModel("header "+j, RS.getMetaData().getColumnLabel(j+1)));
            }

            //Generate table data.
            for (int i = 0; RS.next(); i++) {
                Map<String, ColumnModel> playlist = new HashMap<String, ColumnModel>();
//                System.out.println("Row : " + i );
                for (int j = 0; j < RS.getMetaData().getColumnCount(); j++) {
                    playlist.put(tableHeaderNames.get(j).key, new ColumnModel(tableHeaderNames.get(j).key, RS.getString(j+1)));
                }
                tableData.add(playlist);
            }
            PrimeFaces.current().ajax().update("form:dlgTBL");
            PrimeFaces.current().ajax().update("form:dlgTBL2");
            PrimeFaces.current().executeScript("PF('dlg').show();");
        } catch (SQLException e) {
            System.out.println("Error !!! " + e.getMessage());
        }
    }

    public List<Map<String, ColumnModel>> getSelectedRow() {
        try {System.out.println("Selected Row! " + selectedRow.size());} catch (Exception e) {}

        return selectedRow;
    }

    public void setSelectedRow(List<Map<String, ColumnModel>> selectedRow) {
        System.out.println( "selected size: " + selectedRow.size() );
        this.selectedRow = selectedRow;
    }

    public String getTableColWidths() {
        return tableColWidths;
    }

    public void setTableColWidths(String tableColWidths) {
        this.tableColWidths = tableColWidths;
    }

    public List<Map<String, ColumnModel>> getFilteredData() {
        return filteredData;
    }

    public void setFilteredData(List<Map<String, ColumnModel>> filteredData) {
        this.filteredData = filteredData;
    }
}

以下是html部分

            <p:dialog id="dlgTBL" modal="true" showEffect="bounce" widgetVar="dlg" resizable="false">
                <p:dataTable var="result" id="tbl" widgetVar="dtlTBL"
                                    value="#{liveRangeService.tableData}" 
                                    paginator="false"
                                    scrollable="true"  rowIndexVar="index"  scrollHeight="500" 
                                    scrollRows="50" liveScroll="true"
                                    filterDelay="1100"
                    >
                    <p:ajax event="rowSelect" listener="#{indexBean.onRowSelect}"  />
                    <f:facet name="header">
                        <p:outputPanel layout="inline" styleClass="tabSpacer">
                            <h:outputText value="Global Filter:" />
                            <p:inputText id="globalFilter" onkeyup="PF('dtlTBL').filter()" style="width:150px;margin-left:10px;"/>
                        </p:outputPanel>
                    </f:facet>

                    <p:column width="10">
                        <f:facet name="header">
                            <h:outputText value="Sr." />
                        </f:facet>
                        <h:outputText value="#{rowIndex+1}" />
                    </p:column>

                    <p:columns value="#{liveRangeService.tableHeaderNames}"
                               var="mycolHeader" 
                               width="#{colIndex==0?'10%':colIndex==1?'70%':colIndex==2?'10%':colIndex==3?'10%':'0'}" 
                               columnIndexVar="colIndex" selectRow="true"
                               sortBy="#{result[mycolHeader.value]}"
                               filterBy="#{result[mycolHeader.value]}"
                               filterMatchMode="contains"                        
                               >
                        <f:facet name="header">
                            <h:outputText value="#{mycolHeader.value}" />
                        </f:facet>
                        <h:outputText value="#{result[mycolHeader.key].value}" />
                        <br />
                    </p:columns>

                </p:dataTable>
            </p:dialog>

请告知代码更改。

jsf primefaces
1个回答
0
投票
乍一看,这可能是设置sortBy和filterBy属性的方式。

var="result"

是Map的实例,如果我正确阅读的话。

"#{result[mycolHeader.value]}"

存在问题,您使用.value而不是.key。如果您使用.key,如果我没记错的话,它仍然会返回ColumnModel。因此,设置过滤器的方式是,如果从地图中找到一个,则放置在过滤器中的文本将与ColumnModel实例匹配。

希望我能正确阅读代码,因为这有点令人困惑。特别是您将ColumnModel用作(String,String)元组,而不仅仅是它的预期目的。我认为您可以从

更改tableData的类型

List<Map<String,ColumnModel>>

to

List<Map<String,String>>

因为似乎没有同时使用ColumnModel的两个字段。
© www.soinside.com 2019 - 2024. All rights reserved.