Skip to main content

Creating AJAX Enabled JSF Components

Posted by gmurray71 on May 25, 2006 at 9:08 PM PDT

There is a class of applications and developers that Java Server Faces suites well. JSF is well suited for those that do not want to deal with the intricacies of learning CSS, JavaScript, and DHTML. Once a component is properly created it can be re-used. That said getting all the moving parts in order can take some doing.

Including AJAX Functionality in a Custom JavaServer Faces Component shows the Phase Listener approach of JSF component development.
This is the approach taken with the Java BluePrints AJAX Components/ whih run in Creator and are also used in the Java Pet Store 2.0. Shale Remoting provides a framework for developing JSF components using this approach.

In this example JSF manages the renders the links to JavaScript. JavaScript renders the view on the client. A phase listener is used to manage AJAX call which update the model contained in session scoped beans. There may be some that do not favor an approach where JavaScript is doing much of the rendering of the view as there is not an exact representation of what is being displayed on the client maintained on the server. With some dynamic UIs, especially those that use existing JavaScript libraries out there, it is difficult to keep and exact representation on the client and server. When JavaScript is dynamically managing the view on the client the component developer needs to consider how the data that the component will be validated, how the component is relates to the components around it, and how chatty the client will be with the server. These
issues occur because the phase listener jumps you out of the normal
JSF lifecycle processing for processing AJAX requests.

There are other approaches that are being developed on top of JSF 1.2 and for the future JSF 2.0 that will allow for more granular updates to client/server representation of the view transparently using AJAX. This approach allows existing JSF components to use the standard validators and rendering logic and does not require a developer to have extensive knowledge of
AJAX. This approach is being developed as part of the JSF Extensions.

Check out the tutorial and let us know aht you think.

Related Topics >>