Skip to main content

BluePrints for writing JSF Components that use AJAX

Posted by gmurray71 on June 20, 2005 at 2:36 PM PDT

Tor Norbye from the Creator team,
Ed Burns who is one of the JSF specification leads, and I have created a new BluePrints Solution Catalog entry titled:

Using JavaServer Faces Technology with AJAX.

This document details questions a JSF component developer may face when developing AJAX
enabled components.

  • Should AJAX request handling be done in a separate servlet controller or should it be handled by the JavaServer Faces technology life cycle?
  • How can existing components be AJAX-enabled without rewriting them?
  • Should JavaScript code be embedded in Java code or externalized in a separate script file?
  • How does the programming model differ between component writer and page developer?
  • How should I organize the project structure in my workspace?
  • How should I package the JavaServer Faces objects and JavaScript artifacts into a WAR file or EAR file?

We discuss 3 strategies for developing JSF components that support AJAX which include:

  • A Custom JavaServer Faces Component Renders Client-side AJAX JavaScript and Processes AJAX Requests -
    All AJAX related atrtifacts are rendered by the JSF component. The JavaScript code is also rendered by the JSF component. This is recommended Strategy for developers creating new JSF components where the page developer needs to simply reference the component in the page and everything else is taken care of.
  • Strategy 2: A Custom JavaServer Faces Component with Separate AJAX Controller - A means of separating JSF code from AJAX processing code. In this case the developer is given a little more flexibility at the expense of not being as closely coupled to the JSF runtime. This solution is great for those that want to centralize AJAX processing or potentially use the same AJAX processing code outside of the context of a JSF runtime.
  • Strategy 3: Retrofitting an Existing JavaServer Faces Application -
    This solution focuses on how an exsiting JSF component or application may be AJAXified.

There are two separate entries which implement Strategy 1. These solutions are Autocomplete JSF Component and Progress-Bar JSF Component. Both examples have working component code and sample applications that showcase the components.

For more details on these strategies see: Using JavaServer Faces Technology with AJAX.

Please tell us what you think.