Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Spring Web Flow 2: A boon to JSF developers

JSF 2.0 features elevate SWF 2 to more than a page-flow engine

  • Print
  • Feedback

Page 3 of 4

Validation

JSF offers UI component-level validators for validating individual form fields on the server side. Several JavaScript libraries providing client-side validation capabilities are also available. UI component (form field) validation is found to be segregated, superficial, and insufficient for many Web applications for which validation is a core business concern spanning multiple layers. A new perspective on validation -- domain model constraints -- addresses complex validation requirements. A rich domain model in domain-oriented programming captures business data constraints as part of the application's functional requirements and automatically enforces them with the help of certain Web technologies (such as Seam) on form postback. Sometimes, the same domain model is subject to different validation rules when used on different Web screens; this is described as contextual validation.

Spring Web Flow 2 handles all the validation scenarios I just described. It delivers JavaScript client-side validation through the Spring-JS module in conjunction with a set of Spring Faces tags. Contextual validation methods defined inside a rich domain model should be invoked from the <evaluate> tag within a flow definition. Even better, a validator bean named ${model}Validator can be created to pair up with a domain model Spring bean ${model}. Inside the validator bean, contextual validation methods follow the naming convention of $validate{state}, where state is the ID of a view-state (roughly a Web screen) declared in a flow definition. Spring Web Flow automatically detects, registers, and invokes such a validator on form postback.

In a future release, Spring Web Flow is expected to support declarative validation through XML and annotations, similar to Hibernate Validator (JSR 303: Bean Validation). (I'd like to see the Spring Web Flow team leverage the Bean Validation Framework developed as part of the SpringModules project hosted on Java.net; see Resources.)

JavaScript and Ajax

The Spring-JS module is a lightweight abstraction API that can be implemented through any of the popular JavaScript toolkits, such as Dojo or jQuery. From a Web designer's standpoint, the Spring-JS module progressively enhances a Web page so that the page is still functional in a less capable Web browser. The module also offers basic Ajax functions that Spring Faces leverages in the form of custom JSF UICommand components, which are capable of firing Ajax requests (degenerating to regular HTTP requests when JavaScript is disabled). Inside a flow definition, an Ajax event is processed as an in-page action event: it reloads the same page. An extra <render fragments="clientId"/> tag specifies the clientIds of the JSF UI components to be repainted to avoid a full page refresh. In addition to the built-in Ajax functions, Spring Web Flow 2 supports third-party JSF component libraries such as JBoss RichFaces (formerly Ajax4JSF) and Apache MyFaces Trinidad to enhance the user experience with Ajax-enabled widgets and Scalable Vector Graphics (SVG) images.

  • Print
  • Feedback

Resources

More