Primefaces commandButton not updating datatable. Is update attribute required

jsf, primefaces

Solution

One of the differences between `h:commandButton` and `p:commandButton` is that the second one performs an ajax request by default, while the first executes a plain POST request.

In an ajax request, you must specify what you want to process when form is sent and what to update when response happens. The `p:commandButton` updates nothing by default, that's why your table is not being properly filled.

See also:

- Prime Faces Command Button vs. Default Command Button

- Primefaces commandButton

Problem

I changed my `<h:commandButton>` tag to a PrimeFaces `<p:commandButton>` tag on a search page and my datatable stopped displaying the results. After adding an `update` attribute things worked again. I'm just trying to understand whether it is how I implemented the overall functionality (viewscope, action vs actionListener, etc) or is the `update` attribute really required? ``` <h:form id="search_form"> <p:inputText id="search" value="#{searchBean.searchString}" /> <p:commandButton update="search_form" value="Search" action="#{searchBean.searchByString}" > </p:commandButton> <p:dataTable id="output" var="res" value="#{searchBean.results}" emptyMessage="No results found with given criteria"> etc... ``` ``` @ViewScoped @ManagedBean public class SearchBean { @Inject private SearchRepository searchRepository; private List<Results> res; private String searchString; public SearchBean() { } public String searchByString() { this.setRes(searchRepository.searchBySingleString(searchString)); } ```

Original source

Related problems