How do I process GET query string URL parameters in backing bean on page load?

Yes, you can use the <f:viewParam> to set a request parameter as a managed bean property.

<f:metadata>
    <f:viewParam name="companyId" value="#{bean.companyId}" />
</f:metadata>

You can if necessary invoke a bean action using <f:viewAction> (JSF 2.2+ only) or <f:event type="preRenderView">.

<f:metadata>
    <f:viewParam name="companyId" value="#{bean.companyId}" />
    <f:viewAction action="#{bean.onload}" />
</f:metadata>

When using <f:viewAction> you can even return a navigation outcome.

public String onload() {
    // ...

    return "somepage";
}

When not on JSF 2.2 yet, you can use ExternalContext#redirect() for that. See also among others How to perform navigation in preRenderView listener method.

Note that this is not specific to PrimeFaces. It’s just part of standard JSF. PrimeFaces is merely a component library which provides enhanced ajax and skinnability support.

See also:

Leave a Comment