2
What better way to pass an object to another view in JSF?
I have two pages a query and another with the data to edit a particular object, the query page has a list of objects and each object has the edit button that causes it to redirect to the editing page, I can’t send the object and click on the editing page. My Bean I’m using Viewscoped.
In other languages it is possible to go through POST but in java it is kind of complicated I am not able to adapt. If possible place a code snippet.
I see two simple alternatives: As a Request attribute, if using forward or as an attribute in Flash, if redirect is used.
– Wakim
Ever tried to use a
f:setPropertyActionListener
? Based on a CRUD system, I believe it would work very well. The button would redirect, and within the tags of the button youf:setPropertyActionListener
with the data template to be sent, the code would be more or less this:<f:setPropertyActionListener target="#{bean.objeto}" value="#{objeto}">
.– Gustavo Cinque
For the best user experience and for simplicity of design, I recommend: each button should be a link to the URL of the editing page, passing the ID of the object as parameter. On the edit page you reload the object from this ID received by parameter. Use Sessionscoped only to keep data that is naturally from the session as user credentials and your preferences.
– Caffé