Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

JSF Overview: Java Server Faces

In this article we will see an overview about the MVC Framework Java Server Faces, one of the most used frameworks in Java Web.

Java Server Faces (JSF) is the Java Enterprise Edition technology used in order to develop the web-based user interfaces.JSF technology includes an API which is used to represent the user interface components and helps in order to manage the state. JSF is based on the Model View Controller (MVC) pattern of design. With JSF, the UI state can be managed across the requests made by server and JSF also makes it simple to move the application data from the UI.

Description:

JSF is a powerful framework which helps in order to develop the server side applications and allows the developer to separate the presentation logic and application logic in the web applications. With the help of framework the web development can be done in an easy manner. This JSF framework has the ability to integrate with other frameworks including struts as well and focuses on the user interface side.The JavaBeans are able to get the values from different components of user interface and helps in order to implement the methods of event listeners respectively. The component gets associated with a backing bean through the expression language (EL) of JSF which is similar to the expression language of JSP Standard Tag Library (JSTL).

The mechanism available in JSP is known as the managed bean which allows the user in order to create the backing beans and the objects which get benefit by using this facility are called as the managed beans respectively.The components of user interface helps in order to interact with the end user and these are like the controls of swing including the properties, events and methods. This UI component is basically an object in the stateful form and maintained on the server in order to provide the functionality of the related work.The validators are used in order to ensure the value entered by an end user that if it is either acceptable or not. There is a possibility of more than one validator to be associated with one component of user interface.

The components of user interface have the ability to generate the events and in order to handle those events there is a need to register the listeners.The listeners are assigned to the components in order to integrate the application logic in JSF application.

Overview:

There is an expression language available in JSF which helps to access the elements of collection and the properties of beans. The changes can be applied on the web applications in an easy manner without even changing the code of java by just adding the configurations that are based on XML and on the basis of the file based property. The JSP framework allows the continuous use of MVC in an application.

The attributes of JSF includes the custom tag libraries, components of user interface, renderer, validator, backing beans, converter, the events and listeners, messages and navigation. The two custom tag libraries of JSF are available including HTML and core library. The tag library of HTML helps to avoid the use of hardcode components which results in reusable UI components and the prefix used for this type of library is h that represents HTML. The tag library of core helps in order to register for different events, the validators and related actions on different components and the prefix used for this type of library is f that represents core. The renderer helps to display the user interface component and it basically translates the input entered by the user to the value of component.

The converter in JSF basically converts the value of component to and from a string in order to display that value and these converters have the ability to handle the localization and formatting.The four standard events include value change, action, data model and phase events. The value change events can be generated by using the controls of input and allowing the user in order to enter the values in an input component. An action event generates when the user activates the component of command and the components which generate the action events are known as action sources and the actions source include controls like buttons, hyperlinks.

The actions events are handled by the action listeners and these put an effect in the navigation. The data model events are generated when the component containing data process the row. When an application of JSF receives the request from the client side then the request processing lifecycle gets started and it passes through that process. The information displayed in the form of messages to the user as response.

Importance:

The basic functionality which a normal web application can provide, the JSF application also has the ability to provide this type of functionality in an easy manner. The java server faces (JSF) API is present on the top of servlet API respectively. The technology of Facelets is part of the JSF framework and it is recommended for the presentation logic in order to build the JSF based web application. JSF has defined a standard way in order to handle the resources which include images and other files.

The navigation present in JSF framework helps in order to move from one page to another respectively. There is a specific rule of navigation that informs the user in order to select a page and set of pages and the rules in order to navigate are defined in the configuration file of JSF respectively. In the application of JSF, the states and objects can be saved on any side whether it is client side or the server side. The view implementation consists of the tags that use f as the prefix and the core functionality of JSF for the webpage can be provided through it in an effective manner. The page which includes the elements of JSF should be containing the view tag. JSF has the ability in order to enable the reusability of user interface components that exist in this type of application and to extend them as well in a proper manner.

Screenshots:

Following are the screenshots from the running web application of java server faces.

Java Server Faces (JSF)

Figure 1: Java Server Faces (JSF)

The Figure 1 shows the output when some work is done and web application runs successfully.

Values entered by User and Button Clicked

Figure 2: Values entered by User and Button Clicked

The Figure 2 shows the output when the user enters values and will be directed to new view page after the click and that screenshot is shown in Figure 3.

View Page using JSF technology

Figure 3: View Page using JSF technology

The Figure 3 shows the output of values entered by the user from Figure-02 and these same values are shown in above screen respectively.

Implementation & Code:

Listing 1: index.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
        Hello and Welcome from Facelets
<h:form>
<h1>Person Table</h1>
<h:panelGrid columns="3" columnClasses="rightalign, leftalign, leftalign">
<h:outputLabel value="Person ID: " for="PID"/>
<h:inputText id="PID" label="Person ID" required="true" value="#{Person_Bean.PID}"/>
<h:message for="PID"/>
<h:outputLabel value="Person Name: " for="PName"/>
<h:inputText id="PName" label="Person Name" required="true" value="#{Person_Bean.PName}"/>
<h:message for="PName"/>
<h:outputLabel value="Person Address: " for="PAddress"/>
<h:inputText id="PAddress" label="Person Address" required="true" value="#{Person_Bean.PAddress}"/>
<h:message for="PAddress"/>
<h:commandButton id="eprec" value="Enter_Person_Record" action="finishwork"/>
</h:panelGrid>
</h:form>
</h:body>
</html>

In this xhtml file, the JSF technology is used in order to get the input from user and the design elements are shown in the form of tags.

Listing 2: finishwork.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body><h1>This is the finishwork page in which the results are displayed</h1>
<h:panelGridcolumns="2" columnClasses="normal,normal">
<h:outputText value="Person ID:  "/>
<h:outputText value="#{Person_Bean.PID}"/>
<h:outputText value="Person Name:  "/>
<h:outputText value="#{Person_Bean.PName}"/>
<h:outputText value="Person Address:  "/>
<h:outputText value="#{Person_Bean.PAddress}" />
</h:panelGrid>
</h:body></html>

This is the finishwork page and it is shown to the user as an output using the JSF technology and the related tags used in it.

Listing 3: Person_Bean.java

packagecom.facelets;
importjavax.faces.bean.ManagedBean;
importjavax.faces.bean.RequestScoped;
@ManagedBean(name="Person_Bean")
@RequestScoped
public class Person_Bean {
private String PID;
private String PName;
private String PAddress; 
publicPerson_Bean() {        
    }
public String getPID() {
return PID;
    }
public void setPID(String PID) {
this.PID = PID;
    }
public String getPName() {
returnPName;
    }
public void setPName(String PName) {
this.PName = PName;
    }
public String getPAddress() {
returnPAddress;
    }
public void setPAddress(String PAddress) {
this.PAddress = PAddress;
    }
}

This class contains the attributes, functions including setters and getters. This class attributes are used to get input and display as given in above .xhtml files respectively.

Listing 4: web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
            30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>

This is an automatic generated configuration file when the web application using JSF framework is created.

Hope you liked it. See you next time.



My main area of specialization is Java and J2EE. I have worked on many international projects like Recorders,Websites,Crawlers etc.Also i am an Oracle Certified java professional as well as DB2 certified

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login