Monday, June 14, 2010

Bookmarkable URLs with JSF2



Parameters are now defined in the page itself so a request like:

http://localhost:8080/contactInfo.jsf?contactId=manu%40ffff.se

would have its parameters defined as

<f:metadata>
        <f:viewParam name="contactId" value="#{contactController.email}"/>
    </f:metadata>

If the parameter value isn't specified in the request then the value will be null, so make sure the property receiving the parameter value isn't a primitive (i.e. it must be nullable).

You will also need an action to load data into the view. Any component can have pre-render events attached to it. For example, a form:

<h:form id="contactInfoForm">
            <f:event type="preRenderComponent" listener="#{contactController.loadContact}"/>

All you need to do is declare the parameters to be bound and the action on the page/view you wish to make bookmarkable.

No comments:

Post a Comment