After Patrick's talk this morning, I attended Alex Russell's talk on Dojo in depth (download presentation, blog coverage). I didn't write up a blog post because the juice was gone on my laptop. After plugging in, I checked my e-mail to find a message from Patrick in my inbox.
Subject: At the giants game
Sucka! If you want to go, my buddy has two extra tickets just sitting
here.
So now I'm at the game, using their free wifi to write this post. It's a beautiful day - warm in the sun and cool in the shade. We're in the shade, first level by first base, and I'm drinking a beer. Giants are up 9-0 over the Cubs. Life doesn't get any better than this.
I'm sitting in Patrick Lightbody's presentation on Leveraging AJAX in modern web frameworks. The point of this presentation is to give a preview of what's coming in Struts Action 2.0. There are a number of other good sessions I'd like to go to, particularly Intro to Dojo, but I figured it's better to attend this talk since AppFuse will be moving to SAF as part of 2.0. We're in a fairly small room, and there's about 20-30 people in attendance. With 400+ people at this conference, the other sessions are likely packed.
Ajax is more of a technique, rather than a technology. Commons Ajax techniques include:
- Tabbed pane
- Validation
- Polling
- Tree widget
- Voting
For SAF, there are three core building blocks/tags: <saf:div/>, <saf:a/> (results evaluated as JavaScript) and <saf:submit/>. Divs are where things "happen" and links/submit buttons can trigger events. There are two frameworks used is SAF:
- DWR: Remote invocation service for Java <-> JavaScript
- Dojo: Language/server-agnostic JavaScript framework
There are two styles of Ajax: DOM manipulation (DWR) and partial pages (Dojo). SAF provides three Dojo widgets: BindDiv, BindAnchor and BindButton. The div tag supports the following attributes: href, updateFreq, delay, loadingText, errorText, showErrorTransportText, listenTopics and afterLoading. A simple example is polling - where the remote action returns HTML:
<saf:div href="mailbox.action?id=%{id}" updateFreq="2000"/>
Advanced usage of this tag includes adding a <script> block to the returned HTML. It will be executed when rendered, just like normal JavaScript is.
Tabbed pane is another component that's made up of two tags: <saf:tabbedPanel/> and <saf:panel/>. Rather than specifying content/tags within an <saf:panel>, to use the Ajax version, you simply add remote="true" and href="remoteUrl" to <saf:panel>. I asked about remote="true" being redundant and Patrick agreed it should be implied when an "href" attribute is defined.
SAF also includes the ability to have topic-based events. Dojo supports an event system, which was originally donated by the WebWork developers. Any element, such as a div, may listen to multiple topics. Any element, such as an href or tab header, may notify a topic.
The last thing that Patrick is demonstrating is Validation using DWR. To use it, you will need to use SAF's Ajax theme, as well as have DWR installed and configured. The remote calls to SAF's validation engine return serialized objects rather than HTML "partials". By default, it uses onBlur events to do the validation and all that's required on the client-side is validate="true" on your <saf:form>. Another cool Ajax feature that SAF has is an OGNL Console that gives you a command-line interface to evaluate OGNL expressions.
Patrick's lessons learned from implementing Ajax into WebWork/SAF:
- Simple combinations of the basics can create powerful features, such as the tabbed pane or the tree widget.
- JavaScript inside an HTML block (<saf:div>) or as returned from an action (<saf:a>) can provide valuable glue code.
- The <saf:div/> and <saf:action/> tag have a close and important relationship.
- Understand the important differences b/w Ajax styles (DOM-based vs. snippet-based). Both have their places.
Pitfalls:
- Remember: there is no silver bullet
- At the end of the day, your application is still a web site - don't forget that
- Excessive polling can lead to extreme load and/or thread starvation
- Common functionality, such as the back button and printing, can become difficult or confusing for the user (Dojo can help solve this problem)
- Browser incompatibility can lead to two versions of the same application (see GMail)
The Struts Team hopes to release a preview release of Struts Action 2.0 this week or next, with a final release targeted for August.
When I first saw Mike Stenhouse's CSS Framework, I was very impressed. It's hard to believe it's been a year since I first saw it, and only now am I integrating it into AppFuse. It figures that the week I'm implementing it, Yahoo comes up with something better: Grids CSS. Thanks to Jacob Hookom for e-mailing me the link.
The features of Grids CSS include:
- Full A-grade browser support
- More than 100 page layouts with a single CSS file at just 1.82KB
- Flexible scaling with user font-size adjustments
- Min-width enforcement, regardless of font or viewport size (except IE; helper JS under consideration)
- Abundant DOM hooks for CSS and scripting flexibility
- Source-order independence, allowing you to place your most important body content first in your HTML document
- Self-clearing footer (no matter which column is longer, the footer stays at the bottom)
- Centering within the viewport by default
- Forward-compatibility as standard page structure evolves to claim more screen real estate
- Accommodation for IAB Advertising Units
This is obviously a better solution than the CSS Framework, especially since it seems to be well-documented and allows source-order independence. However, it suffers from a similar problem: there's a lack of good-looking designer-styled templates that showcase how cool this library is. There is hope though, Andreas Viklund (a well-known open source template designer) is talking about a Modular CSS Template. The question is: will he re-use Yahoo's Grids CSS or invent his own?
[Yahoo's Grids CSS] is almost exactly what I was working on - but much smaller and probably better than I would have done it. The main difference is that I added a few extra layers to the cake: Make-up (layout-wide styling for typography, forms, headers, links and so on), Colorscheme (just what it sounds like) and Backdrops (background images). Designers can add each layer separately. If you have a site based on the template and you want to change the styling - add a new Make-up. It is a matter of cutting and pasting blocks of code into the CSS, even a beginner with no CSS design skill can do that. If you want to use different colorschemes for different pages - just add more colorschemes and call it from the colorscheme class of each page. One line of code to change, and the effect is very obvious?
It's cool to see there's lots of work going on in this space. While AppFuse 1.9.2 will include the CSS Framework, there's nothing stopping us from using a different solution for 2.0. I'm leaning towards moving to Yahoo's solution, but it's likely I'll be heavily influenced by Andreas' work in this space. Of course, since Yahoo's library is open source, it might make sense for Andreas to simply contribute to this project and improve what they've already done.