How to use URL Query Parameters in JSF

I had to access query parameters from a GET request in a JSF page.

The URL looks like http://localhost:8080/tel/person=Martinelli and this should trigger a search.

With ViewParam this is very easy to achieve:

<f:metadata>
    <f:viewParam name="person" value="#{searchBean.person}" />
    <f:viewAction action="#{searchBean.search}"/>
</f:metadata>

The viewParam would fill the query parameter person in the property person of the SearchBean JSF backing bean and viewAction will trigger the search action on page load.

Easy – isn’t it!?