When a lazy datatable is created programmatically (using binding and valExp) sortField is always null, sortorder Ascending, filter map {}. This happens when you click the sort field or enter a string in the filter field.
When the same is done WITHOUT binding, everything in the xhtml view everything works as advertised. I also looked at the PhaseListener boot sequence and did not find anything else in both cases, only it does not work at first.
TestController - @ViewScoped. Tried with versions PF 3.5, 3.4.2, 3.3.1, 3.3.
Am I doing it wrong?
View
<p:dataTable binding="#{testController.datatable}" /> <p:dataTable value="#{testController.testModel}" var="val" rows="5" lazy="true"> <p:column sortBy="#{val}"> #{val} </p:column> </p:dataTable>
generations
datatable = new DataTable(); datatable.setValueExpression("lazy",createValueExpression("true", Boolean.class)); datatable.setValueExpression("rows",createValueExpression("10", Integer.class)); datatable.setValueExpression("value",createValueExpression("#{testController.testModel}", DataModel.class)); datatable.setVar("val"); Column column = new Column(); column.setValueExpression("sortBy", createValueExpression("#{val}", String.class)); HtmlOutputText output = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE); output.setValueExpression("value", createValueExpression("#{val}", String.class)); column.getChildren().add(output); datatable.getChildren().add(column);
model
public List<String> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) { List<String> modelMock = new ArrayList<String>() { { add("abc"); add("def"); } }; if (LOGGER.isDebugEnabled()) { LOGGER.debug("load()"); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("first " + first + " pageSize" + pageSize); LOGGER.debug("sortField -> " + sortField); LOGGER.debug("sortOrder -> " + sortOrder); LOGGER.debug("filters -> " + filters); } this.setRowCount(modelMock.size()); return modelMock; }
debug output
11:12:24,426 DEBUG TestModel:33 - load() 11:12:24,426 DEBUG TestModel:37 - first 0 pageSize10 11:12:24,426 DEBUG TestModel:39 - sortField -> null 11:12:24,426 DEBUG TestModel:40 - sortOrder -> ASCENDING 11:12:24,426 DEBUG TestModel:41 - filters -> {}
The second data type is proof that when it is not used with binding, it works
11:21:25,677 DEBUG TestModel:33 - load() 11:21:25,677 DEBUG TestModel:37 - first 0 pageSize5 11:21:25,677 DEBUG TestModel:39 - sortField -> val 11:21:25,677 DEBUG TestModel:40 - sortOrder -> DESCENDING