To avoid double sending caused by the impatience of pressing the submit button, you can use a piece of Javascript that disables the submit button a few ms after onclick.
Example:
<h:commandButton id="foo" value="submit" action="#{bean.submit}" onclick="setTimeout('document.getElementById(\'' + this.id + '\').disabled=true;', 50);" />
To avoid double presentation, by clicking the "Back" button and ignoring the browser warning that you can resend the data, you need to implement Post-Redirect- Get Template (PRG) .
In JSF, this can be done mainly in two ways. Or using <redirect/> in <navigation-case> :
<navigation-case> <from-action>#{bean.submit}</from-action> <from-outcome>success</from-outcome> <to-view-id>/page.jsf</to-view-id> <redirect/> </navigation-case>
or by calling the ExternalContext#redirect() method in a bean:
public void submit() { doYourThing(); FacesContext.getCurrentInstance().getExternalContext().redirect("page.jsf"); }
The only drawback is that redirect implicitly creates a new request, thereby discarding the original request, including all its attributes (and therefore also managed by all beans and FacesMessages ). In some cases, it does not matter, but in other cases it will certainly be. I do not do Seam, but if I am right, they solved this problem by using the so-called conversation area and automatically saving FacesMessages via redirection. You can take advantage of this.
Balusc
source share