If you want to share information between views there are two typically used alternatives you could consider.
Pass information to the next view as a GET parameter
In this case you'll use a JSF component generating a plain navigational link and attach a query parameter to that link, like in:
<h:link value="Next page" outcome="/view-kitten"> <f:param name="id" value="#{kitten.id}"/> </h:link>
In the receiving page the parameter is available via:
<f:metadata> <f:viewParam name="id" value="#{kittenBean.id}/> </f:metadata>
More excellent information can be found in What can
<f:metadata>
and<f:viewParam>
be used for?Pass information to the redirected view using
Flash
In this case you're performing a redirect in an action method of a command component and will attach necessary data to the target view using
Flash
object:<h:commandButton value="Next page" action="#{bean.next}"/>
with
public String next() { //do business job FacesContext.getCurrentInstance().getExternalContext().getFlash().put("kitten", selectedKitten); return "/view-kitten?faces-redirect=true"; }
It will be available in the target view via EL with
#{flash.kitten}
or programmatically withFacesContext.getCurrentInstance().getExternalContext().getFlash().get("kitten")
.An extended example can be found in JSF2.0 - How to get the values in other jsf page's bean in request scope.
The last thing to note is: don't abuse HTTP session. You shouldn't pollute the session with information that belongs elsewhere.