使用lazydatamodel时,列(表主体)在数据表中不可见

时间:2019-05-27 05:19:51

标签: jsf primefaces lazydatamodel

使用LazyDataModel不会在数据表中显示列。

我实现了自定义LazyDataModel,并且实现了load方法init。但是,当我将数据模型作为值传递给数据表时,不会渲染/显示列。但是当我将其作为列表传递时,将显示/显示列。

我的LazyDataModel类

public class SearchPmrLazyDataModel extends LazyBaseDataModel<SearchDTO> {
 public SearchPmrLazyDataModel() {
    }

    public void setData() {
        if (searchCriteria == null) {
            searchCriteria = new PmrSearchCriteriaDTO();
        }
       setWrappedData(pmrService.searchPmr(searchCriteria, teamId));
    }

    @Override
    public List<PmrSearchResultViewDTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {

        setData();
        searchCriteria.setPageRequest(determinePage(first, pageSize));
        List<PmrSearchResultViewDTO> data = this.cachedData;

                // rowCount
        int dataSize = data.size();
        this.setRowCount(dataSize);

        // paginate

        if (dataSize > pageSize) {
            try {
                return data.subList(first, first + pageSize);
            } catch (IndexOutOfBoundsException e) {
                return data.subList(first, first + (dataSize % pageSize));
            }
        } else {
            return data;
        }
    }

    @Override
    public void setRowIndex(int rowIndex) {
        if (rowIndex == -1 || getPageSize() == 0) {
            super.setRowIndex(-1);
        }
        else
            super.setRowIndex(rowIndex % getPageSize());
    }

    @Override
    public Object getRowKey(PmrSearchResultViewDTO obj) {
        return obj.getId();
    }
} 

我的豆子

public LazyDataModel<SearchDTO> getCorresLazyDataModel(String selectedTabName, String selectedStateName, String selectedStateName2) {
       //returns corresponding lazy data model according to a business logic
        return getLazyDataModel(selectedTabName, selectedStateName, selectedStateName2);
    }

我的XHTML页面

<p:dataTable
    value="#{formBean.getCorresLazyDataModel(pmrStatusTab, pmrState, pmrState2)}"
    var="pmr" id="pmrStatusResultTable#{pmrStatusTab}#{pmrState}"
    widgetVar="pmrStatusResultTable#{pmrStatusTab}#{pmrState}"
    style="overflow: auto; width: auto! important; table-width:fixed"
    rows="10" rowKey="#{pmr.id}" rowStyleClass="odd, even"
    reflow="true" scrollWidth="#{formBean.scrollWidth}"
    scrollable="true" scrollRows="10" paginator="true" lazy="true"
    selectionMode="single" selection="#{formBean.selectedPmr}">
    <p:ajax event="rowSelect" process="@this"
        listener="#{formBean.onRowSelect}" />
    <p:columns value="#{formBean.columns}" var="column"
        columnIndexVar="colIndex" sortBy="#{pmr[column.property]}"
        sortable="true">
        <f:facet name="header">
            <h:outputText value="#{column.header}" />
        </f:facet>
        <h:outputText value="#{pmr[column.property]}" />
    </p:columns>
</p:dataTable>

仅当我直接传递数据模型时,才会渲染/显示列。如果我将值作为列表传递,则会显示它们,是否缺少任何内容?

0 个答案:

没有答案