Monday, June 3, 2013

Re: Dynamically generated HTML and GWT

I think you kind of misuse the *.wrap() method. They are meant to be used with static html pages that you want to enhance with GWT.

I think what you really want for now is to extend Widget and overwriting onBrowserEvent(), e.g.

MyServerFormWidget extends Widget {
  
  MyServerFormWidget() {
    setElement(Document.get().createDivElement());
    sinkEvents(Event.ONCLICK);
  }

  public void setServerGeneratedHtml(String html) {
    getElement().setInnerHTML(html);
  }

  @Override
  public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);
    int eventType = DOM.eventGetType(event);
    if(eventType == Event.ONCLICK) {
       //check event target element, if its the submit button
       if(formSubmitButtonHasBeenClicked(event)) {
          event.preventDefault();
          onSubmitClickIntercepted();
       }     
    }
  }

  private void onSubmitClickIntercepted() {
    //do your stuff, e.g. read form data and fire higher level events like fireEvent(new SubmitEvent(formData)); so you could use GWT-RPC/RequestFactory/RequestBuilder to send the form data to the server. That way you don't have to write Servlets directly.
  }

}


-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment