我使用primefaces懶數據表在JSF頁面如下圖所示:回到Bean的屬性不更新primefaces數據表排序操作
<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>
正如你可以看到,有一個數據表上方的搜索面板,包含用戶可以通過填充縮小結果的參數。對於後面的bean中的每個搜索字段,存在一個相應的屬性,如下所示。
@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;
}
}
當我按下「搜索按鈕」後豆
更新,並且它包含用戶已經輸入了「searchField」值。 但是,當我嘗試使用「recordId」列上的排序箭頭對網格進行排序時,我的請求轉到後臺bean的「getListOfRecords()」方法,但「searchField」值爲null。
如何指導數據表排序操作以更新後臺bean中的搜索字段?
[如何選擇正確的bean作用域?](https://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope) – Kukeltje