1. What is JSF ?

The full form of JSF is JavaServer Faces. JavaServer Faces is a standard Java framework for building user interfaces for Web applications. It simplifies the development of the user interface, which is often one of the more difficult and tedious part of Web application development.

It simplifies the development process by following ways

It provides a component-centric, client-independent development approach to building Web user interfaces, thus improving developer productivity and ease of use.

It simplifies the access and management of application data from the Web user interface.

It automatically manages the user interface state between multiple requests and multiple clients in a simple and unobtrusive manner.

It supplies a development framework that is friendly to a diverse developer audience with different skill sets.

It describes a standard set of architectural patterns for a web application.

2. What are the available features in JSF 2 ?

Foundational Features

System Events: This feature provides a very fined-grained level of detail to observe and act upon the JSF runtime as it processes requests.

Resources: This feature allows the JSF runtime to serve up static resources, such as style sheets, scripts, and images, in addition to the previously available capability to serve up JSF pages.

Facelets: Facelets began as an open-source JSF extension that provided first-class templating and easy integration between markup and the JSF API. This made the experience of writing JSF pages easier and more maintainable. Facelets is included in the core JSF specification in version 2.0.

Big Ticket Features

Ajax: This feature enables JSF views to communicate with the server directly from the browser without requiring a full-page refresh of the browser window. Ajax is an essential element of most production-quality Web applications currently in production.

Composite Components: This feature enables creating true JSF components as aggregations of other JSF components. With this feature, it is easy to build your own custom JSF components and to refactor your existing views into reusable components, complete with listeners, attributes, and events.

Partial State Saving: One of the biggest complaints against JSF has been the amount of memory it consumes to maintain view state between requests. This feature dramatically reduces the amount of memory for this purpose, as well as greatly simplifying the API for handling state when developing custom components.

View Parameters: Another big complaint against JSF is its insistence on using POST for all inter-page navigations.

Medium-Sized Features

Navigation Enhancements: JSF 2.0 bring several enhancements to navigation, including bookmarkability, navigation without XML navigation rules, conditional navigation, support for the POST-REDIRECT-GET pattern, the flash, and runtime inspection of navigation rules.

Exception Handling: JSF 2.0 now has a central ExceptionHandler through which all exceptions are funneled. This enables easily constructing an error page that uses JSF components.

Expression Language Enhancements: Several new implicit objects have been introduced, and the EL now supports method invocation on arbitrary Java methods, including parameter passing.

Validation: An entirely new Java specification has been developed to address validation, JSR-303 Bean Validation. This specification integrates well with JSF 2.0.

New Scopes: In addition to the flash scope, JSF 2.0 also provides a mechanism for defining custom scopes.

Small New Features

Access to the FacesContext is now available during application startup and shutdown.

The UISelectItems child of components that extend from UISelectOne and UISelectMany can now refer to arbitrary collections of Objects.

JSF now allows the developer to tell the runtime in what phase of the software development lifecycle the runtime is executing. This “ProjectStage” feature enables the runtime to output more informative error messages and hints as the project is being iteratively developed.

Annotations may obviate the need for XML. For nearly every XML element that can reside in a faces-config.xml file, there is now a Java language annotation that can be used in its place. This annotation feature, combined with the “navigation without XML navigation rules” feature, makes it possible to build JSF applications entirely without a faces-config.xml file.

3. What is JSF request processing lifecycle ?

When a JSF-enabled XHTML page is requested or when the user invokes an action on a UI component in a JSF-enabled XHTML page, then the exact sequence of events that occur on the server in order to fulfill the request to view or submit a JSF page is given below.

Submit Web page -> Create or Restore the view -> Apply values from form -> Ensure values are valid -> Update model with valid values -> Fetch a new view if necessary -> Render view -> View Web page

4. What is managed bean in JSF ?

This is a fancy term for a way to hook together different parts of your application without introducing too much interdependencies (tight coupling). It is a POJO (Plain Old Java Object) that conforms to JavaBeans naming
conventions and an officially registered Java class for a JSF application. In order for a JSF application to refer to Java classes, and their methods and properties, it has to be available in the Java classpath and registered in faces-config.xml or with the appropriate annotation.

5. What is the naming convention for a managed bean in JSF ?

The @ManagedBean annotation may have a name attribute, but if this is omitted, the system will take the unqualified Java classname, lowercase the first letter, and use the result as the name. For the below example the default name(if no name provided using name attribute) for a managed bean will be userBean

If name is provided for the managed bean then that name would be used. For the below example the name is userMBean.

6. What is <h:message/> in JSF ?

If you want to show an error message for a particular required input field then you can use <h:message/> JSF element.

7. What is <h:messages/> in JSF ?

If you want to show error messages for all required input fields then you can use <h:messages/> JSF element.

8. What runtime does during the execution of the JSF lifecycle ?

Determines if this is a page request or a resource request. If this is a resource request, it will serve the bytes of the resource to the user-agent. Otherwise, it will load the Facelets or JSP page.

Creates a server-side representation of the UI.

Produces markup suitable for rendering in the browser.

The JSF lifecycle automatically keeps track of the changed portions of the state, so the client-side view is always in step with the server-side view.

9. What are JSF lifecycle phases ?

Restore View: Restores or creates a server-side component tree (View) in memory to represent the UI information from a client.

Apply Request Values: Updates the server-side components with fresh data from the client.

Process Validations: Performs validation and data type conversion on the new data.

Update Model Values: Updates any server-side Model objects with new data.

Invoke Application: Invokes any application logic needed to fulfill the request and navigate to a new page if needed.

Render Response Saves state and renders a response to the requesting client.

10. Who determines which page needs to be shown to the client ?

The navigation handler is responsible for determining whether to simply respond with the same page, or to navigate to a new page.