Which is the best way to implement the Primefaces commandButton for saving a form in a CRUD application handling the browser refresh and back buttons in the most intuitive manner?
PS: The CRUD code is credited to BalusC Recommended JSF 2.0 CRUD frameworks
But this uses standard <h:commandButtons>
Here is relevant code from BalusC's post
<p:commandButton value="Save_A" action="#{CRUD.saveEdit()}" ajax="true" update="@all"/>
<p:commandButton value="Save_B" action="#{CRUD.saveEdit()}" ajax="false"/>
<p:commandButton value="Save_C" action="#{CRUD.saveEdit2()}" ajax="true" />
<p:commandButton value="save_D" action="#{CRUD.saveEdit2()}" ajax="false"/>
--
@ManagedBean
@ViewScoped
public class CRUD implements Serializable {
public void saveEdit() {
dao.update(item);
this.item = new ChecklistClass();
edit = false;
}
public void saveEdit2() {
dao.update(item);
this.item = new ChecklistClass();
edit = false;
util.redirectWithGet(); // <- Eliminates popup with browser refesh
}
Save_A and B I don't like because after a successful submit, if you refresh the browser, you get the popup about resending information previously submitted.
Save_C and D I prefer, they both seem to work intuitively. Refreshing the browser does not give you the popup asking to resend data and the back button works somewhat intuitively.
But would one be better for network requests? Since saveEdit2() has a redirect should I not use the p:commandButton with Ajax="true"? In other words would that do a double redirect?