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.
Asked
Active
Viewed 3,392 times
5
-
1Might be helpful to clarify what the "double submit problem" is. – Jason Hall Dec 29 '10 at 03:32
-
@Jason Hall stupid users double-clicking buttons and hence the same request firing twice – Sean Patrick Floyd Dec 29 '10 at 15:40
2 Answers
2
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.

Jason Hall
- 20,632
- 4
- 50
- 57
-
I believe you want to add button = event.getSource() to the onClick() method. – DwB Dec 29 '10 at 18:52
-
I was envisioning having `button` be a final member of the class, but that should work too. – Jason Hall Dec 29 '10 at 19:14
0
This will be helpfull for you -
final Button btn = new Button("Open");
btn.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
btn.setEnabled(false);
openMethod(name, new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
btn.setEnabled(true);
}
public void onSuccess(Void result) {
MessageBox.alert(info, "Opened Window", null);
btn.setEnabled(true);
window.hide();
}
});
}
});

Pawan Pareek
- 469
- 4
- 7