Java Server Faces (JSF) is "Swing for server-side applications". It presents a dynamically controlled sequence of screens through the user's web browser. Forms in the web screen can have widgets that the user can use to send data to the application. The data is sent when the user clicks on a form button. The application can respond by sending a new screen to the browser. An example login application can be run here.

JSF has these parts:

Some earlier web technologies intermingle HTML and code from programming languages such as Java. JSF keeps different languages in different files. JSF is well-supported by IDEs such as NetBeans and Eclipse.

There are two structures associated with a JSF application.

A JSF application is deployed as a WAR file. The structure of the WAR file is similar to the development structure except that Java source files are replaced by Java class files.

The WAR file for the login application has this structure:

In NetBeans the login application appears in the Projects pane as:

The Configuration Files folder is not shown expanded in the above screenshot. It contains the same files as the Web Pages/WEB-INF folder.

Unlike JSF, some earlier web technologies intermingle HTML and programming language code. Disadvantages include:

This is a simplified life cycle of a JSF request initiated by the browser. The important fact for now is that request data is extracted, decoded, and verified.

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.

  • Construct the component tree if this is the page's first request.
  • Otherwise, retrieve the component tree, retaining form information between requests.
  • Iterate over component tree, allowing objects to store their values.
  • Convert form strings to submitted values (objects of any type).
  • Perform correctness checks.
  • Update beans that are wired to components.
  • Execute the action method of the button or link that caused form submission.
  • The string result is used by the navigation handler to look up next page.
  • Encode the response and send it to the browser.

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:

  • More complex bean management (CoreJSF Ch. 2)
  • More complex navigation (CoreJSF Ch. 3)
  • A variety of standard screen tags (CoreJSF Ch. 4)
  • Templates that give a uniform appearance to different screens in an application (CoreJSF Ch. 5)
  • Screen tags for presenting data in tabular form (CoreJSF Ch. 6)
  • Data conversion and validation (CoreJSF Ch. 7)
  • Event handling (CoreJSF Ch. 8)
  • Custom view components (CoreJSF Ch. 9, 11)
  • Using AJAX (CoreJSF Ch. 10)
  • Access to external services such as databases (CoreJSF Ch. 12)