GWT: what are the best practices for building a web2.0 interface with GWT?
I am no artist/designer so usually my GUIs well, you know... I've tinkered a bit with GWT and I was able to get sensible results but I feel I have used contrived ways of getting those results.
If the community feels this question could help: please put one开发者_运维百科 recommendation per answer.
We identified the following high-level best practices for GWT 1.6/1.7 (just after 3 months of research and development):
- Use design patterns (MVC/MVP, Command for GWT-RPC, Composite for widget composition, Observer for event bus, etc.);
- Isolate application logic with MVP by abstracting out widget classes and views using presenter display interface and GWT characteristic interfaces (such as HasValue, HasText, etc.);
- Use dependency injection with gin on a client and Guice on a server (or stick with existing server framework like Spring);
- Use GWT Composite in combination with HTMLPanel to drive your views with html, css and MVP;
- Use mock testing based on isolation of application logic with MVP;
- Implement Event Bus with GWT HandlerManager;
- Use GWT modules to effectively optimize code compilation;
- Use client, shared, and server packages when organizing GWT modules;
We have developed a large HR portal with GWT. The look and feel of this application can be customized for different deployments. To do this we use fragments of HTML to generate parts of the GUI i.e. bits of HTML are sent to the client in DTOs and then stuffed into HTML widgets. This approach works well for mastheads, logos, menus and so on.
Other things (e.g. capture forms) are generated using normal GWT code.
We use "pages" (different history tokens identifying where you are) as this makes it possible for users to use bookmarks in a meaningful way. We also generate links to different parts of our system in emails and so on.
Our application is composed of a lot of "higher level" widgets we call "Portlets" arranged into "pages" defined in XML. Again this makes it possible to customize the functionality for a given installation.
All this is done using a framework (GWT Portlets) that we have published as open source.
- The best practice is to do everything from Java, so your HTML only acts as a placeholder. Yes I hate to say this, but if you're still messing around with the HTML it only makes your life more miserable.
- If you still have the only web mindset, which is separating webapps into several html pages, throw that away, get the building the desktop app (that run on the browser) mindset. Think of building swing apps.
- If you need to style the GWT components, override the GWT's css classes in your own CSS.
- The last best practice is to decouple your application with the MVP pattern. The reason is because you can basically write the whole application in one Java class, which of course can lead you to maintenance hell, and problems if you are working with several peers.
精彩评论