he Java Enterprise Edition 5 platform includes JavaServer Faces (JSF) technology, which provides a mature and extensible user interface component model. The design of this model makes it easy for application developers to create custom components by extending the standard components included with JSF and to reuse these components across applications. Creating a component shields the page author from the complexities of AJAX by rendering all the HTML and JavaScript code that is required to incorporate AJAX capabilities into an application. There are many ways to wrap AJAX functionality using JSF, and this document will briefly mention several strategies. You can see the detailed write up on each related startegy in the following documents:
- Using the PhaseListener Approach. This is a simple approach that handles many common AJAX enabled JSF component creation cases.
- Accessing Static and Dynamic Resources. This is an evolution of the PhaseListener approach which adresses some of the issues with the simpler PhaseListener approach.
- Using a Servlet Controller with JSF to handle AJAX requests. This approach decouples the AJAX request fulfillment from the JSF life cycle when this functionality is not desired.
- Additional strategies will be coming soon also!
Solution
Developers who want to include AJAX support in JSF applications are faced with many design questions. For example,
- Should AJAX request handling be done in a separate servlet controller or should it be handled by the JSF 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?
Developers who want to include AJAX support in JSF applications have more than one strategy to choose from. We will cover two types of startegies at this time. One point to stress is that the programming model differs between component writer and page developer. The strategies covered here can be used to add AJAX support to just a part of your application or to create re-useable JSF components. Though it is a bit of extra work to create an AJAX enabled JSF component, it makes it very easy for page authors to re-use that component.
In the first strategy, using a PhaseListener to fulfill AJAX requests in JSF components, the JSF life cycle and the custom component handles or decorates the AJAX requests. The second strategy, using a Servlet to act as a controller, introduces a Servlet to process AJAX requests to be used with the JSF components. In the second strategy, all asynchronous requests will therefore be handled outside of the JSF life cycle processing. In general, the first startegy is more common and the second startegy is more of a special case.
References
- Understand the JSF component model. The JavaEE 5 Tutorial on Creating JavaServer Faces Components describes the necessary artifacts needed to create custom JSF components.
0 comments:
Post a Comment