DataTable列分页问题

时间:2017-03-05 12:37:04

标签: primefaces jsf-2.2 pf-datatable

使用showcase示例,带有p:columns和分页的Declarative p:dataTable。

我希望以编程方式工作,并在页面加载网格上显示数据。当我点击编程的分页时,所有数据都会丢失。它仍然显示正确的行,但我不确定为什么数据丢失。

enter image description here

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

参考:  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

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

    </p:panel>

1 个答案:

答案 0 :(得分:0)

我通过使用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>