I would like to implement a search box in my web-app. A JSF <h:form>
should redirect me to products.xhtml?search=somestring. It should work the same as the following piece of HTML:
<form action="products.xhtml" method="GET">
<input type="text" name="search" />
<input type="submit" value="Submit" />
</form>
All the solutions of similar problems I came across does the redirection to another page without querystring
<h:form>
<h:inputText value="#{product.searchString}"/>
<h:commandButton value="Submit" action="products?faces-redirect=true&includeViewParams=true"/>
</h:form>
.
<h:form>
<h:inputText valueChangeListener="#{product.searchStringChanged}" />
<h:link value="Submit" outcome="products">
<f:param name="search" value="#{product.searchString}" />
</h:link>
</h:form>
OR builds the querystring but redirects to the same page. The reason of not using pure HTML is to keep the benefits of the JSF session management.
EDIT
With the help of BalusC's post and https://blogs.oracle.com/enterprisetechtips/entry/post_redirect_get_and_jsf, I came up with following solution:
<f:metadata>
<f:viewParam name="search" value="#{product.search}" />
</f:metadata>
<h:form>
<h:inputText value="${product.search}"/>
<h:commandLink action="products?faces-redirect=true&includeViewParams=true" value="Search"/>
</h:form>