简体   繁体   English

Backbean属性在primefaces数据表排序操作上未更新

[英]Back bean attributes not updated on primefaces data table sort action

I'm using primefaces lazy data table in a jsf page like below: 我在jsf页面中使用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>

As you can see, there is a search panel above the dataTable which contains parameters that user can narrow the result by filling them. 如您所见,在dataTable上方有一个搜索面板,其中包含用户可以通过填充参数来缩小结果范围的参数。 There exists a corresponding attribute for each search field in the backing bean like below. 备用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;
    }
}

when I press the "searchButton" the back bean gets updated and it contains the "searchField" value which the user has inputted. 当我按下“ searchButton”时,背景bean得到更新,并且包含用户输入的“ searchField”值。 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. 但是,当我尝试使用“ recordId”列上的排序箭头对网格进行排序时,我的请求转到了back bean的“ getListOfRecords()”方法,但是“ searchField”值为空。

How can I instruct the data table sort actions to update the search fields as well in the back bean? 如何指示数据表排序操作以更新Back bean中的搜索字段?

如果可行,请尝试使用会话范围,以便搜索字段值可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM