Reputation:
I've been trying this for a few days now with no luck.
final FormPanel form = new FormPanel(new NamedFrame("test"));
form.setAction("/designer");
form.setMethod(FormPanel.METHOD_POST);
VerticalPanel panel = new VerticalPanel();
form.setWidget(panel);
final TextBox tb = new TextBox();
tb.setName("style");
panel.add(tb);
panel.add(new Button("Submit", new ClickHandler() {
public void onClick(ClickEvent event) {
Window.alert("submitting to:" + form.getTarget());
form.submit();
}
}));
form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
public void onSubmitComplete(SubmitCompleteEvent event) {
Window.alert("complete");
Window.alert(event.getResults());
}
});
In Hosted Mode, nothing happens after the "Submitting to" alert fires. In Chrome, the form loads in a separate tab, but the POST itself is empty. In Firefox and IE, again, nothing happens after the alert. Any ideas?
I've set up a servlet at /designer that outputs the request header and body from any page requests. I can hit this servlet from a plain HTML page and see the expected output. From GWT, no request ever appears (except for Chrome, in which the request shows up, but with an empty body).
Upvotes: 6
Views: 7185
Reputation: 766
I know this post is 3 years old, but for the sake of any googler like me who lands here, this are the conditions for the OnSubmitCompleteEvent to be fired:
Use the no-arg constructor to build the form: FormPanel f = new FormPanel();. As mentioned in the Javadoc:
Creates a new FormPanel. When created using this constructor, it will be submitted to a hidden <iframe> element, and the results of the submission made available via {@link SubmitCompleteHandler}.
So it is the only one which DOES trigger the form submission complete event when successful.
Make sure that the action being called returns a response with content-type:"text/html"
One solution, if you still need to use your external NamedFrame, is to watch for the LoadEvent on the frame. It gets fired when the frame starts loading, meaning that the response from server arrived: ...
NamedFrame frame = new NamedFrame("test");
frame.addLoadHandler(new LoadHandler()
{
void onLoad(LoadEvent event)
{
//your code here
}
});
Hope it helps!
Upvotes: 0
Reputation: 915
Try moving form.setWidget(panel);
to the bottom.
Also, make sure that you add the form to the container panel i.e. add(form);
, not the vertical panel.
Upvotes: 2
Reputation: 5135
Your code is almost identical to the example on the FormPanel API, therefore I must assume that the logic is correct.
Does a servlet exist at "/designer"? The documentation for SubmitCompleteHandler states that the onSubmitComplete event only fires if the submit is successful.
Here is a thread containing some sample code for writing a servlet that handles the form post: http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/77e68fcb9097debc
Upvotes: 1