160 likes | 366 Views
Java Web Development with NetBeans IDE. -- Kai Qian. Chapter 5 JavaServer Faces (JSF) Technology. Objectives. Overview of JSF. JSF lifecycle. Overview of JSF. JavaServer Faces (JSF) is a component model based framework for web server application.
E N D
Java Web Development with NetBeans IDE --Kai Qian Chapter 5 JavaServer Faces (JSF) Technology
Objectives • Overview of JSF. • JSF lifecycle.
Overview of JSF • JavaServer Faces (JSF) is a component model based framework for web server application. • JSF was developed by the Java Community Process (JCP) Program, a community of web application professionals. • The goal of JSF is to provide a standard framework to simplify the development process of Java web server applications.
Overview of JSF, contd. • JSF is a vendor-independent technology standard for the Java enterprise software industry. • JSF facilitates web server UI component development with the concept of event-based interaction just like the Java Swing UI desktop components on client sites that allow you to drag-and-drop UI components to build a web server application. • JSF provides a UI component API to support server UI component development.
Overview of JSF, contd. • JSF is a further development from the well-known MVC architecture and Struts framework for web server design. • The JSP page centralizes the Controller of MVC-1. • The Servlet Controller centralizes the Controller in MVC-2 to handle the initial request input data, to set up data beans for the Model (data) supported by JavaBeans, and to forward the data results to various JSP pages for presentation in the View module.
Overview of JSF, contd. • Among the many advantages of JSF over MVC-2 and Struts, two of the most important are the better separation of behavior and presentation of server-side components by the event interaction model and the server UI component support. • The event-driven model (instead of the HTTP request/response model) provides high abstraction in the server design so that the UI components trigger events and the event listeners handle and respond to the events.
Overview of JSF, contd. • The best advantage of this feature is the separation of the JSF component design in the design window and the code development in the code editor window so that different professionals can focus on their own work independently. • JSF has a collection of APIs for the UI components with the capacity to manage their states and handle events and validation.
Overview of JSF, contd. • The high abstraction of JSF UI components also makes it possible to support the independence between UI components and a particular rendering. • In JSF, the data is maintained in the UI components. • Another very important feature of JSF is its ability to manage component state, process component data, validate user input, and handle events.
Overview of JSF, contd. • A JSF UI component mainly focuses on its presentation and its related underlying business logic is taken care of by a managed bean. • One of the main features of JSF is that it has not only been designed for coding experts but also for other professionals working together on different project aspects.
Overview of JSF, contd. • A JSF application is supported by the JSF tag library, JSF API, JSP, and a Java Servlet, which are running in a Servlet container on a web server. • JSF mainly includes the following: 1. A set of APIs that represent and manage the state of components and help server-side validation, event handling, page navigation, data conversion, etc. 2. A JSP custom tag library to create UI components in a view page.
JSF Lifecycle, contd. • Every JSF request from a client goes through a JSF lifecycle with the following steps: • 1. A client JSF request is directed to the FacesServlet controller via the Servlet container on the web server first according to the configuration specified by the servlet and servlet-mapping tags in the faces-config.xml file. The FacesServlet creates an object called FaceContext, which has ServletRequest and ServletResponse objects for request and response processing. The FaceContext object lets a LifeCycle object start the JSF lifecycle processing phases.
JSFLifecycle, contd. 2. JSFconstructs or restores a component tree for the UI components on the requested JSP page. 3. Then JSP sets UI components with new values from clients and hook event handlers for the components. 4. JSF applies the validation and converter logic to the component data and validates the new values according to the component validation rules. If invalid, go to step 7 to respond client with an error message.
JSF Lifecycle, contd. 5. Update the managed beans or backing beans with the validated data. If any errors, go to step 7 to respond client with an error message. 6. Invoke application, business logic, and page navigation. If any action is taken, e.g., a form submission button is pressed, the event handler is invoked and the page may be forwarded to the next response page and the result is rendered to clients by the ServletResponse object. The FacesServlet controller plays the important role of traffic control and the traffic rules are set in the faces-config.xml configuration specification file. 7. Finally, the JSF rendering responses are sent back to the clients.
Chapter 5 • The End