Example GWT App – Newsletter Signup

I decided to try out GWT on a simple project: providing a small newsletter signup box on a conference micro site. The idea was that after checking that a valid email had been submitted -- and complaining with a DHTML popup if it wasn't -- that email would be sent to a backend web service (asynchronously, of course). While the async XHR request was percolating, the newsletter box would display a thank you message, then fade away. A cookie would also be set, preventing the newsletter box from displaying during the lifetime of the browser session.

This just barely qualifies as AJAX, since I'm doing just one crummy little "Hello World!" communication with the backend. Still, it gets rid of the whole painful navigation to a signup screen, so that's a win in the AJAX column.gwt_example.jpg

OK, so just 150 lines of code later (yeah, I know), I have my little box. The site is software500.pathf.com where you can see the newsletter box in the bottom right corner. Please be kind and don't sign up your goofy friends.

 

A few lessons from the excercise:

  • GWT doesn't remove the need for Javascript. I found myself writing a few funky methods like this:
     public native void setCookie(String cookie, String value) /*-{    document.cookie = cookie + "=" + escape(value) + ";Path=/"; }-*/;         public static native String getLocationHref() /*-{    return $wnd.location.href; }-*/; 
  • The GWT documentation is not complete. What is does talk about is pretty solid, but the fact that Google is not a shrinkwrap software company is pretty evident. Let's hope they hire some gifted technical writers and such for the general release of GWT.
  • Debugging in the hosted mode is pretty handy. Not that an application of this simplicity needed a whole lot of debugging.
  • One of the gaps in documentation is that it isn't very task based. Suppose you have a question like "How do I include a third party jar file?" You can dig through the documentation site and maybe come accross an explanation of the syntax of the MyApp.gwt.xml file and on another page the directory structure of a GWT project. Putting the two together takes a bit of noodling. That's definitely a steep start to the learning curve that doesn't need to be there.
  • Spend some time with the more essoteric parts of the documentation, like how to write modules. Also, take a spin through the gwt.js file and see how it parses the gwt meta tags. This will ease your pain down the road when your GWT app and html page sit in different directories.

In my previous article on GWT Developments, I've pointed out several good resources for getting started, including the GWT newsgroup. Make liberal use of them.

Related posts:

  1. Ajax Forms – Enhancing the user experience
  2. Does Google Eat its Own Dogfood?
  3. Markdown support for GWT in 42 seconds
  4. GWT: DOM and Opacity
  5. More GWT Developments

Comments: 1 so far

  1. discouraging… The last thing I want to do is be writing multi-line Javascript in my Java file… Thanks for the look into it, this is a very valuable blog post and I’ll spread it around.

    Comment by Ivan, Thursday, June 15, 2006 @ 6:12 pm

Leave a comment

Powered by WP Hashcash

Launch: Pathfinder Newsletter

    Get a monthly update on best practices for delivering successful software.

    Subscribe via email


    Subscribe via RSS      RSS icon

Topics

Search

WordPress

Comments about this site: info@pathf.com