How to prevent DoubleSubmit in a GWT application?

后端 未结 2 1072
我在风中等你
我在风中等你 2021-01-05 19:16

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 bu

2条回答
  •  再見小時候
    2021-01-05 19:31

    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() {
            @Override
            public void onSuccess(String result) {
              // do stuff
              processing = false;
              button.setEnabled(true);
            });
          });
        }
      }
    });
    

    That's the gist of it.

提交回复
热议问题