JSF:数据表未更新

JSF: Datatable is not updating

我正在学习 JSF 并遇到以下问题:

Xhtml class:

    <h:form><p:inputText  value="#{tempView.tempName}" e:placeholder="Search Name">
    </p:inputText>
    <p:commandButton id="search" value="Search" action="#{tempView.searchName()}" update="dataTable">
    </p:commandButton>
    <p:commandButton value="clear" action="#{tempView.clearSearchCriteria()}" update="dataTable">
    </p:commandButton>


<p:dataTable id="dataTable"
    value="#{tempView.tmpList}"
    var="tempVar" rowStyleClass="#{tempView.rowStyleClass(tempVar)}"
    rows="12" paginator="true"
    paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink}
    {LastPageLink} {RowsPerPageDropdown}"
    rowsPerPageTemplate="5,10,15" scrollable="true">

    <p:column headerText="First Name" sortBy="#{tempVar.firstName}">
        <h:outputText value="#{tempVar.firstName}" />
    </p:column>

    <p:column headerText="Last Name" sortBy="#{tempVar.lastName}">
        <h:outputText value="#{tempVar.lastName}" />
    </p:column>

    <p:column headerText="Institute / Practice Name" sortBy="#{tempVar.Address}">
        <h:outputText value="#{tempVar.instituteName}" />
    </p:column>
</p:dataTable>

Java Class:

public String searchName() {

    System.out.println("Executed");


    /**

        logic of refining list..
    **/

}

我面临的问题是..首先调用 getter 和 setter 方法,然后调用操作 'searchName' 并在执行操作方法之后。它没有调用 getter 和 setter 因为我的数据表没有更新。 action方法'searchName'有提炼datatable中list的逻辑。 如果您需要任何其他信息,请告诉我。 谢谢

不使用 Action ,而是使用 ActionListener。您需要将 bean 中的方法更改为 return void 并添加 ActionEvent 作为参数。