I'm using primefaces lazy data table in a jsf page like below:
<h:form id="searchForm">
<h:panelGroup id="searchFields">
<h:outputText value="searchField"/>
<p:inputMask
id="txtSearchField"
dir="LTR"
mask="9?999999999999"
maxlength="12"
value="#{myBackBean.searchField}" />
<h:commandButton
id="searchButton"
value="search"
action="{myBackBean.searchAction}" />
</h:panelGroup>
<p:dataTable
id="resultTable"
var="res"
value="#{res.listOfRecords}"
paginator="true" paginatorPosition="bottom" rows="10"
rowsPerPageTemplate="5,10,15"
lazy="true">
<p:column headerText="recordId" sortBy="#{res.recordId}">
<h:outputText value="#{res.recordId}" />
</p:column>
</p:dataTable>
</h:form>
As you can see, there is a search panel above the dataTable which contains parameters that user can narrow the result by filling them. There exists a corresponding attribute for each search field in the backing bean like below.
@Component
@Scope("request")
public class myBackBean {
private String searchField;
private LazyDataModel<RecordsDto> listOfRecords;
@Autowired
MyService myService;
public String getSearchField() {
return searchField;
}
public void setSearchField(String searchField) {
this.searchField = searchField;
}
public LazyDataModel<OperationsDto> getListOfRecords() {
return listOfRecords;
}
public void setListOfRecords(LazyDataModel<RecordsDto> listOfRecords) {
this.listOfRecords = listOfRecords;
}
public void searchAction() {
// doing the search and filling the list
listOfRecords = ...;
return listOfRecords;
}
}
when I press the "searchButton" the back bean gets updated and it contains the "searchField" value which the user has inputted. But when I try to sort the grid with the sort arrow on the "recordId" column, my request goes to "getListOfRecords()" method of the back bean, but the "searchField" value is null.
How can I instruct the data table sort actions to update the search fields as well in the back bean?