I am working on a JSF application whose homepage has a search input field with a command button to submit the search. Once the user clicks the search button it should search and show the results page. I am having problem with passing the parameter from the home view to the results view. My code is as follows :
<h:form id="searchForm">
<p:inputText styleClass="enterSearch" size="50" value="#{searchController.searchText}" onkeypress="if (event.keyCode === 13) {document.getElementById('searchForm:submitSearch').click();
return false;
}"/>
<p:commandButton id="submitSearch" styleClass="enterSearch" value="Search" label="Search" action="#{searchController.search(searchController.searchText)}" />
</h:form>
Bean is
@ManagedBean(name = "searchController")
@ViewScoped
public class SearchController implements Serializable {
.....
public String search(String query) {
//What goes here? Use FacesContext Attributes?
return "searchResults";
}
...
The search method returns searchResults.xhtml page This page displays the search results. How can I pass the search query to the searchResults view and initialize the backing bean for searchResults? Any ideas please?