• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GWT and HTTP post requests

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
I have been reading that GWT plays fine with HTML forms post requests.
Usually, we sent the post request to some kind of command, we run a little of Voodoo at the command and then forward the request to another resource (JSP for example).
How GWT fits in these cases?
What I don't understand is if I'm posting from GWT page, what to do in the command once handling the request is finished? forwards to another resource?
Would you mind shedding some lights here?
Thanks for your time.
 
author
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John,

In the background, posting a form in GWT works in the same way as normal. You hit the submit button, the data in the form is submitted to some resource on your server (JSP page, PHP, .Net Perl etc etc) that does some action on the data and then returns a result to the web browser.

In the GWT view, you create your form in a FormPanel adding widgets (e.g. text boxes, radio buttons etc) to the panel, and then add a FormHandler. When you submit the form, the onSubmit() method of the handler is executed - here you can check the form is filled in correct etc. Once the submission is complete, then the onSubmitComplete() method of the handler is called, so you can handle any submission complete (e.g. result) from the server.

In execution, by default GWT creates a hidden frame on your page where the actual submission of the form and return of result occurs. GWT handles the moving of data around, e.g. the result returned to this hidden frame is the value that is passed to the form handler's onSubmitComplete() method.

You can see some example code here: http://code.google.com/webtoolkit/documentation/com.google.gwt.user.client.ui.FormPanel.html

So, it's all done with smoke and mirrors

Hope that answers the question.

//Adam
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, a typical flow is:
1. GWT page posts to /action.jspa command object.
2. action.jspa command do the Voodoo on behalf of us.
3. action.jspa command forwards the request to nicePage.jsp
4. The user is now see nicePage.jsp
Right?
Or the generated markup of nicePage.jsp will be shown on the GWT page (in the same way we use Prototype Ajax.Updater)?
 
Adam Tacy
author
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
almost, apart from step 4 generally gets posted to a hidden frame in your GWT application.

In the onSubmitComplete() method of the FormHandler you can programmatically see the contents of that hidden frame and act appropriately - which might include parsing the result, or placing the contents directly into the DOM.

(If you provde the FormPanel a your own named frame, then the standard functionality of using hidden frames is replaced with all the action taking place in the visible frame)

//Adam
 
author
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With FormPanel you have the option of not using the hidden frame. You could have the results go to a named frame, like "_self", which would replace the contents of the page.
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

almost, apart from step 4 generally gets posted to a hidden frame in your GWT application.

In the onSubmitComplete() method of the FormHandler you can programmatically see the contents of that hidden frame and act appropriately - which might include parsing the result, or placing the contents directly into the DOM.


So, I have to create a hidden frame and assign an ID to it in my GWT host page?
In case GWT will create it on the fly, how I'm supposed to access it with DOM since I don't its ID or name?
Thanks in advance.
 
Adam Tacy
author
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Todd:

So, I have to create a hidden frame and assign an ID to it in my GWT host page?



You don't have to worry about it; GWT will create the frame for you if you just use the constructor FormPanel().

However, GWT gives you the option of creating a frame yourself if you want, and then you can pass that (or a reference to _self/ _top etc) to the constructor of the FormPanel - this can actually be useful for debugging if you want to see the actual raw data being returned by your service.

Originally posted by John Todd:

In case GWT will create it on the fly, how I'm supposed to access it with DOM since I don't its ID or name?



Again, you don't have to worry. In the the actual FormHandler onSubmitComplete() method you get access to the results through a FormSubmitCompleteEvent object that is passed in as a parameter - I was being a bit lazy with the method definition, in reality you would have:

form.addFormHandler(new FormHandler() {
public void onSubmitComplete(FormSubmitCompleteEvent event) {
String result = event.getResults());
}

public void onSubmit(FormSubmitEvent event) {
}
});

The onSubmitComplete() method is called by GWT code when the form submission is completed and GWT passes in a FormSubmitCompleteEvent object from which you can access the contents of the hidden frame - through that event's getResults() method.

//Adam
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getResults() method is returning the proper value in FireFox but returning 'null' in Internet Explorer
any idea, what could be the reason? why get Results() method always returns null in IE
 
reply
    Bookmark Topic Watch Topic
  • New Topic