In JSF 2 you can pass around ids, Strings other things that can be sent as request parameters with either f:viewParam or @ManagedProperty (i.e. discussion here).
However, I would like to pass around objects between views, from view1 to view2. My backing beans are @ViewScoped. I have tried the following:
<f:setPropertyActionListener value="#{view1Bean.myObject}" target="#{view2Bean.myObject}" />
This creates a view2Bean on view1, which no longer exists when viewing view2. So, the view2Bean.myObject is null, because the property was never set on the specific instance of view2bean.
I considered using the Flash scope, which seems to be exactly the tool for this. However, I read BalusC somewhere saying that it is broken in Mojarra, which I’m using.
What is the best way to pass around objects between views?
You could just pass the unique ID of the object as a parameter to the next view and attach a
Converterto the<f:viewParam>.This will as of the current Mojarra version only fail whenever the views are in a different path (folder) due to the way how the Flash cookie works. If they are in the same path (folder) then it should work just fine.