简体   繁体   English

DataTable列分页问题

[英]DataTable Columns Pagination Issue

Using the showcase example the Declarative p:dataTable with p:columns and pagination works. 以展示示例为例,带有p:列和分页的Declarative p:dataTable。

I would like to get this working in a programmatic way and on page load grid is shown with data. 我想以编程方式进行此工作,并在页面上显示带有数据的加载网格。 when i click on the pagination for programmatic , all the data is lost. 当我单击分页进行编程时,所有数据都会丢失。 It still show the correct rows , but i am not sure why the data in missing. 它仍然显示正确的行,但是我不确定为什么缺少数据。

在此处输入图片说明

Project : https://github.com/ravihariharan/primefaces-test Primefaces 6 , JSF 2.2.14 , On Tomcat 8.5.3 项目: https : //github.com/ravihariharan/primefaces-test Primefaces 6,JSF 2.2.14,在Tomcat 8.5.3上

Refer : 1. main/webapp/columns.xhtml 2. main/java/org/primefaces/showcase/view/data/datatable/ColumnsView.java 请参阅:1. main / webapp / columns.xhtml 2. main / java / org / primefaces / showcase / view / data / datatable / ColumnsView.java

@PostConstruct
public void init() {
    cars = service.createCars(50);

    createDynamicColumns();

    createProgramaticGrid();
}

private void createProgramaticGrid() {
    DataTable dataTable = createDataTable();

    dataTable.setId("progCars");
    dataTable.setVar("progCar");
    dataTable.setValueExpression("value", createValueExpression("#{dtColumnsView.cars}", List.class));

    dataTable.setPaginator(true);
    dataTable.setRows(10);
    Columns columns = createColumn();
    ValueExpression columnValues = createValueExpression("#{dtColumnsView.columns}", List.class);
    columns.setValueExpression("value", columnValues);
    columns.setVar("column");

    OutputLabel headerValue = createOutputLabel();
    headerValue.setValueExpression("value", createValueExpression("#{column.header}", String.class));
    columns.getFacets().put("header", headerValue);

    OutputLabel value = createOutputLabel();
    value.setValueExpression("value", createValueExpression("#{progCar[column.property]}", String.class));

    columns.getChildren().add(value);

    dataTable.getChildren().add(columns);

    FacesContext context = FacesContext.getCurrentInstance();
    UIViewRoot viewRoot = context.getViewRoot();
    viewRoot.findComponent("form:mainGridBody").getChildren().add(dataTable);

}

private OutputLabel createOutputLabel() {
    return (OutputLabel) createComponent(OutputLabel.COMPONENT_TYPE);
    // return new OutputLabel();
}

private Columns createColumn() {
    return (Columns) createComponent(Columns.COMPONENT_TYPE);
    // return new Columns();
}

private DataTable createDataTable() {
    return (DataTable) createComponent(DataTable.COMPONENT_TYPE);
    // return new DataTable();
}

private UIComponent createComponent(String componentType) {
    return FacesContext.getCurrentInstance().getApplication().createComponent(componentType);
}

columns.xhtml columns.xhtml

    <h3>programmatic</h3>
    <p:panel id="mainGridBody">

    </p:panel>

i got this working by using javax.faces.FULL_STATE_SAVING_VIEW_IDS. 我通过使用javax.faces.FULL_STATE_SAVING_VIEW_IDS使其工作。

javax.faces.FULL_STATE_SAVING_VIEW_IDS javax.faces.FULL_STATE_SAVING_VIEW_IDS

<context-param>
    <param-name>javax.faces.FULL_STATE_SAVING_VIEW_IDS</param-name>
    <param-value>/columnsprog.xhtml</param-value>
</context-param>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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