Passing parameters to a view scoped bean in JSF

Solution 1:

Using view parameters is the most proper way for your case. You don't really need to perform a REDIRECT, but a plain GET request:

<h:button value="Go to details" outcome="carDetails">
    <f:param name="carId" value="#{currentCar.id}" />
</h:button>

This will point you to this address: carDetails.xhtml?carId=1

After that, in your carDetails.xhtml page, grab the view param and load the info for that car:

<f:metadata>
    <f:viewParam name="carId" value="#{carDetailBean.carId}" />
    <f:event type="preRenderView" listener="#{carDetailBean.loadData}"/>
</f:metadata>

Where CarDetailBean#loadData just loads the info for your car to display with the given id, already set into the bean.

See also:

  • Difference between h:button and h:commandButton
  • What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?