Java Server Faces (JSF) is "Swing for server-side applications". It provides much of the plumbing for JavaServer Pages (JSP), which is used in conjunction with Servlets for developing web applications.
JSF has these parts:
JSF is well-supported by IDEs such as NetBeans and Eclipse.
There are two structures associated with a JSF application.
The application is deployed as a WAR file. The JSF framework imposes a deployment structure on its contents.
Application developers work in an IDE such as NetBeans or Eclipse. The IDE imposes a development structure. It uses a build script to produce the WAR file from the development structure.
Some earlier web technologies intermingle HTML and code from programming languages such as Java. JSF keeps different languages in different files.
Note that the WAR file does not include Java source files.
This is the structure that application developers work with in NetBeans:
Unlike JSF, some earlier web technologies intermingle HTML and programming language code. Disadvantages include:
Professional web designers prefer not to deal with embedded code.
Professional programmers are notoriously unqualified for graphic design.
The scope of the JSF implementation is restricted to the presentation tier, but it is designed so that programmers can "hook in" business logic for manipulating their own data model.
Database persistence and web services are outside scope of JSF, but "hooks" are provided for dealing with them.
Model-View-Controller Architecture
Data Conversion
Validation and Error Handling
Internationalization
Custom Components
AJAX Support
Alternative Renderers
Overview text.
JSF pages contain hierarchies of user interface (UI) components.
In the login example, the parent component is a form (h:form) and the children are the name field (h:inputText), password field (h:inputSecret), and button (h:commandButton).
Each tag has a tag handler class. These collaborate to create a component tree data structure:
Each component has a renderer that produces HTML output.
All text that is not a JSF tag is simply passed through.
The JSF tags are converted to HTML by their renderers.
For example, the renderer for the UIInput component converts
<h:inputText value="#{user.name}"/>into
<input type="text" name="unique ID" value="current value"/>
The JSF framework obtains the current value of user.name from the user bean.
The JSF framework generates unique IDs for HTML elements so that they can be associated with beans. This process is called encoding.
User fills in form fields and clicks a command button.
Browser sends the form data to the server as a string of ID/value pairs in a POST request.
IDs allow UI components to associate the data sent with appropriate beans and actions:
The big picture:
This is the life cycle of a JSF request initiated by the browser. Everything in the above diagram is taking place on the server.
With AJAX (Asynchronous JavaScript with XMLHttpRequest) the response need not be an HTML page. It can be information used by the browser to dynamically modify its current web page. JavaScript is the language used on the browser. XMLHttpRequest is a JavaScript function for asynchronous data transfer.
More advanced JSF applications still use Java Beans for data management, and they frequently use the mechanism illustrated in the login example for navigation between web pages. In addition, JSF supports the following: