Primefaces Datatable sortField null and filters map {} when creating programmatically

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 
+4
source share
1 answer

There is a problem between anchor elements and the @ViewScoped area. You can read more information here: http://balusc.blogspot.com/2010/06/benefits-and-pitfalls-of-viewscoped.html#HeyTheresPitfallsInTheTitle

One solution is if you want to keep your binding and your current scope in order to enable full state savings for components. You can customize it for the specified page by adding this to your web.xml

 <context-param> <!-- For Bug Fixing Viewscope beans with binding component attributes --> <param-name>javax.faces.FULL_STATE_SAVING_VIEW_IDS</param-name> <param-value>/faces/myPageWithBindings.xhtml</param-value> </context-param> 
+1
source

All Articles