Chapter 9. JavaServer Faces and Ajax


JavaServer Faces (JSF) is a user interface framework that runs on a Java application server and renders a user interface to a client. The most popular client is a web browser running on a desktop computer, but JSF is not limited to web applications. Although it is a complex technologylearning JSF isn't a trivial taskonce you've learned it, you will be able to build many web applications faster. If you are unfamiliar with JSF, you can learn it by reading the JavaServer Faces Specification, Sun's tutorial (http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSFIntro.html), or one of the reference books written on the subject. Hans Bergsten, one of the spec's contributors, has written an excellent introduction and reference called JavaServer Faces (O'Reilly). I learned JavaServer Faces using that book and Sun's JSF tutorial (which is actually part of the J2EE tutorial) as my primary tools.

JavaServer Faces provides a clean separation between the business logic and presentation layers. It establishes a one-to-one mapping between HTTP requests and components. This mapping allows a finer-grained model for a web application than a typical JSP application can provide. With JSF, there is a lifecycle for communication between the web page and the Java beans that makes up the backend. There are listeners that listen for events and renderers that create a view for display to the user. Writing a JSF application is not unlike writing a Swing applicationand it's radically different from writing a typical web application.

There are several ways to use Ajax with JavaServer Faces:

  • Use an external service to handle the XMLHttpRequest. This strategy avoids the JSF lifecycle.

  • Use a custom JSF component to render the JavaScript and process the Ajax XMLHttpRequests. In this case, the request is processed through the JSF lifecycle, just like any other JSF request.

  • Use an external lifecycle to handle the Ajax requests.

This chapter presents one way to add Ajax to a JSF application: using a custom JSF component. We will process the Ajax request through the JSF lifecycle.




Ajax on Java
Ajax on Java
ISBN: 0596101872
EAN: 2147483647
Year: 2007
Pages: 78

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net