This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Google Web Toolkit Applications : what's the best design pattern?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I recently started out using GWT for the (obvious) reason that, while I regard myself as a Java 'expert', I know (and wish to know :-) very little about Javascript.

Shortly after starting out, I fell back on to the MVC pattern, using the 'main' (entry point) class as the Controller, creating a bunch of View(s) - using the well-trodden View interface and AbstractView - as well as a bunch of command (and could I fail in implementing an AbstractCommand and SimpleCommand?)

So, it all looked gorgeous and very OO-like...
but it left me wondering: is this the best way of doing things in GWT? was I re-inventing the wheel?

And, on a related note: it is my understanding that one does all the styling and UI-related stuff in the CSS(s) - although GWT gives you more than a few backdoors to do that directly in Java. Is this really the accepted gospel, or is there a middle ground? a better way?

Will be looking forward to reading your views and the book!

Cheers,
Marco.
 
author
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GWT is very intuitive to a Java developer and I think your on the right track using Model-View-Controller. Of course you don't have to use MVC, but it is a well understood way to organize a client facing application. The big benefit with MVC is the decoupling of the major parts of your application. Being able to use the model or controller separately for performance or unit testing or even switching views are big pluses. Also, if you're working on a team using common patterns like this your colleagues are going to understand what your doing a lot quicker.

In my book each of the five example applications, chapter 6-10, are based on MVC design. The controller is typically loaded from GWT's EntryPoint.onModuleLoad method. It does the job of loading the model from a server, and populating/listening to the application
s view. The model objects are usually just POJOs which can be used directly over GWT RPC to a Java Servlet. You can also build your model from GWT's XML or JSON DOM. For the view, GWT has a user interface framework similar to Java's AWT with widgets and an event model. There are basic widgets like buttons, complex widgets like a tree, and layout widgets called Panels. You can construct your own widgets from scratch or by combining other widgets using GWT's Composite.

As for styling your interface, CSS is the way to go. CSS is fairly standard between browsers (see http://www.gwtapps.com/?p=22 for an important exception). It's declarative and easy to learn. It's also important to separate user interface styles from your application code since you may need to have a less technical professional make your app look great.

Recently, however, I've been digging into the GWT incubator project which has a StyleInjector class allowing you to bundle CSS, including background images, inside the single JavaScript download of your application. This may be the start of more sophisticated handling of CSS where GWT compiles it similar to how it handles JavaScript. Here's a post where a couple of GWT engineers are talking about it: http://groups.google.com/group/Google-Web-Toolkit-Contributors/browse_thread/thread/cb9605b64edf0154
[ November 13, 2007: Message edited by: Ryan Dewsbury ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!