views:

1033

answers:

3

The example from FormPanel's javadoc says:

"...Assuming the service returned a response of type text/html, we can get the result text here (see the FormPanel documentation for further explanation)..."

However the javadoc doesn't explain a bit about this topic. Has anyone found how to get the HTML response sent back from server after a form submission?

+3  A: 

Add a FormHandler to your FormPanel, and in onSubmitComplete you will receive a FormSubmitCompleteEvent. Invoke its getResults() method to obtain the result.

form.addFormHandler(new FormHandler() {
    public void onSubmit(FormSubmitEvent event) { // validation etc }

    public void onSubmitComplete(FormSubmitCompleteEvent event} {

         Window.alert(event.getResults()); // display the result
    }

};
Robert Munteanu
Ain't working for me. event.getResult() called on GWT 1.6 on Mac returns null.
ciukes
Are you sure you're actually returning something from the file upload? I.e. if your handing this off to a servlet, use response.getOutputStream().write("Works!"); response.getOutputStream().flush();
Robert Munteanu
A: 

//=========== in the client side:

SubmitCompleteHandler sch = new SubmitCompleteHandler() { public void onSubmitComplete(SubmitCompleteEvent event) { //get back the data results that had input the .xml String dpsString = event.getResults();

//And do your wanted action with the result
System.out.println(dpsString);
}};

uploadForm.addSubmitCompleteHandler(sch);

//=========== in the server side:

// parse and handle file, e.g. if there is an xml file ... InputStream fileImputStream = uploadItem.getInputStream(); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(fileImputStream); doc.getDocumentElement().normalize(); System.out.println("Root element of the doc is " + doc.getDocumentElement().getNodeName()); ... //Response to the request with the result
dpsString = doc.getDocumentElement().getNodeName(); response.getWriter().write(new String(dpsString));

Charilaos
A: 

Following the answear from "Robert Munteanu" you should look at:

http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/ui/FormPanel.SubmitCompleteEvent.html

And there you can see :

getResults

public java.lang.String getResults()

Gets the result text of the form submission.

Returns:

the result html, or null if there was an error reading it

Tip:

The result html can be null as a result of submitting a form to a different domain.

Roman M