Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent DoubleSubmit in a GWT application?

To clarify what double submit is: When the user clicks on a submit button twice, the server will process the same POST data twice. To avoid this (apart from disabling the button after a single submit), most web frameworks like Struts provide a token mechanism. I am searching for the equivalent of this in GWT.

like image 254
Vidhya Avatar asked Nov 05 '22 04:11

Vidhya


1 Answers

If you want to avoid submitting twice, how about:

boolean processing = false;
button.addClickHandler(new ClickHandler() {
  @Override
  public void onClick(ClickEvent event) {
    if (!processing) {
      processing = true;
      button.setEnabled(false);
      // makes an RPC call, does something you only want to do once.
      processRequest(new AsyncCallback<String>() {
        @Override
        public void onSuccess(String result) {
          // do stuff
          processing = false;
          button.setEnabled(true);
        });
      });
    }
  }
});

That's the gist of it.

like image 162
Jason Hall Avatar answered Nov 15 '22 13:11

Jason Hall