How to prevent form re-filling in Seam?

I have a simple form that I do not want to accidentally transmit several times.

I can easily block the user from several clicks when they first see the page, but I can’t control their clicking on the "Back" button.

So, while working with Struts, I decided that the form view marker is the way to go.

Is there an easier way? Is this functionality already in Seam? If this does not happen, how should I build this functionality in Seam?

// EDIT // Just an explanation here, I DO NOT need something, a click. This has already been decided.

A specific use case is as follows: The user clicks a button. The action is in progress. For some indefinite time in the future, the user repeatedly presses the "Back" button to return to the page using the button. The user presses the button again.

How can I protect against this?

+6
java forms jsf seam
source share
3 answers

Seam comes with the s: token component, and this is what you are looking for: http://docs.jboss.org/seam/2.2.0.GA/reference/en-US/html/controls.html#d0e28933

+6
source share

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.

+6
source share

With a4j / RichFaces, use the a4j: queue or assign a queue to a button. Thus, a few clicks will be queued, and only one of them will really pass. The way to install it globally for your application, if you use RichFaces (we did this instead of setting up the queue everywhere), you should put the following into your web.xml:

 <context-param> <param-name>org.richfaces.queue.global.enabled</param-name> <param-value>true</param-value> </context-param> 
+2
source share

All Articles