Tech News

Component-Based Web Development Using JSF 2

JavaServer Faces (JSF) is a component-based framework for developing web applications. The distinctive feature that sets component-based frameworks apart is the ability to create and distribute reusable UI components. In general, a component represents an abstraction, a well-defined contract with the implementation details hidden from the user of the component. That is, the user of the component does not need to know the internal mechanisms of the component in order to be able to use it.

Struts and Spring Web MVC alleviate the increasing complexities of building sophisticated user interfaces for the Web, but these web frameworks are not component-centric and therefore unqualified for engineering truly reusable UI components. To that end, different web frameworks, such as Tapestry and Wicket, emerged to offer a component-centric approach to web application development.

However, because of a lack of existing standards for component-centric development, the ways in which these web frameworks implemented reusable UI components appeared to an experienced web developer to be tedious or limited. JSF standardizes component-based web development and provides numerous and broad-ranging UI components to reduce the complexities in web application development. JSF provides out-of-the-box reusable UI components so that the application developers can concentrate on the application’s business logic rather than striving to develop and maintain dynamic and rich user interfaces.

JSF is the evolution of a few frameworks such as Struts and was inspired by Swing’s component model. JSF represents, and requires, a paradigm shift to let you think in terms of components instead of requests and responses. Its goal is to make web development rapid by promoting and standardizing an ecosystem to engineer reusable UI components.

Faces Servlet

Faces Servlet is the controller in the MVC and implements the Front Controller pattern that intercepts every interaction between Face let’s (the view) and the model. Faces Servlet is configured through annotations on managed beans, converters, components, renderers, and validators or optionally through the faces-config.xml descriptor file.

VDL

JSF uses a view declaration language (VDL) to display a page to the client on various devices such as the desktop, portables, and so on. The default VDL for JavaServer Faces (JSF) is Facelets, but JSF allows multiple VDLs, such as JSP.

JSF EL

In the Hello World application, you saw how to access managed bean properties and invoke managed bean actions using EL expressions with the delimiters #{ and }. The EL used in JSF 1.0 and 1.1 (and later in JSP versions 1.2 and 2.0) was an extension of the EL that was part of the JSP Standard Tag Library (JSTL), as explained. The difference between JSF EL and JSP EL is that of evaluation. any ${} expression that appears in the page is evaluated immediately during page rendering. Such expressions are called immediate expressions. JSF allows expressions to be available both during the rendering of the page and when that is posted back again. This type of expression in JSF is called a deferred expression and is expressed with the delimiters #{}.

Converter and Validator

JSF provides out-of-the-box converters to convert its UI component’s data to objects used in a managed bean and vice versa. For example, they convert a component’s Date value to and from String values that come from the HTML markup. JSF also provides out-of-the-box validators to validate its UI components to ensure that the value entered by the user is valid. These tags can, for example, validate a range of Long or the length of a string.

Events and Event Listeners

When the user clicks a button or link on the JSF page, a JSF UI component triggers an event. To handle such an event, an event listener is registered on the managed bean. The UI component calls the event notification on the event listener for the specific event. As you have seen, JSF pages consist of a tree of components.

This tree of components is managed by the JSF request processing life cycle behind the scenes. To understand the JSF request[1]processing life cycle, first, you will create a Hello World web application, and then through this application, you will learn how the JSF life cycle works behind the scenes.

Summary

JSF is a component-based MVC framework, at the heart of which is the UI component model; this model allows the development of a web application’s view from collections of standard, out-of-the-box, reusable UI components. Unlike Struts and Spring Web MVC, the JSF life cycle performs mundane and recurring request-processing tasks in well-defined phases, allowing the developer to concentrate on the business logic of the web application.

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button