I am build a CRUD web application using JSF and have made a add form for creating a new entity which gets persisted to the database. On a succeful save I would like the user to get navigated to a page where the details of the newly created entity will be displayed.
More in detail what I wan't to do is to create a navigation rule where on a succeful save the user gets navigated to "dilutionDetail.xhtml". Which I do using "faces-navigation.xml". And this part works fine.
My problem is that I need to pass a parameter that allows me to fetch the id of the newly created entity. Bellow is the commandButton in the add form.
<p:commandButton value="Save" action="#{dilution.save()}">
<f:actionListener binding="#{dilution.prepareForSave()}" />
</p:commandButton>
The entity gets persisted when dilution.save()
is called (which also returns 'saved' on success to be used in the navigation case). dilution
is a view scoped managed bean.
Save looks like this:
public String save(){
das.create(dilution);
return "saved";
}
After das.create(dilution)
has been called the dilution
entity will have the id that I want to pass as a parameter. How can I do this?