JSF 2, Spring 4, Hibernate 4 and Maven Integration

In this tutorial I will show you how to integrate JSF 2, Spring 4, Hibernate 4 and Maven. In the previous example Spring 3, JSF 2 and Hibernate 3 integration example , I have shown how to integrate JSF 2, Spring 3 and Hibernate 3 but I have not used maven there.

For this tutorial we will create maven based web project in Eclipse.

If you already have an idea on how to create a maven project in Eclipse will be great otherwise I will tell you here how to create a maven project in Eclipse.


The following configurations are required in order to run the application

Eclipse Kepler
JDK 1.8
Tomcat 8
Have maven installed and configured
JSF 2, Spring 4, Hibernate 4 dependencies in pom.xml

Now we will see the below steps how to create a maven based project in Eclipse Continue reading “JSF 2, Spring 4, Hibernate 4 and Maven Integration”

Immediate attribute example in JSF

This tutorial will show you what is the purpose of using immeditae attribute in JSF. Although the request processing lifecycle processes the different phases in a consistent manner, the execution order of the phases can be altered for special cases. For example, you may want to add a Cancel button to a form. When clicked, it will skip all validation and simply navigate to another page without processing the values in a form. To alter the processing order of the request processing lifecycle, simply set the immediate attribute on a component.

For this tutorial we will create maven based web project in Eclipse.

If you already have an idea on how to create a maven project in Eclipse will be great otherwise I will tell you here how to create a maven project in Eclipse. Continue reading “Immediate attribute example in JSF”

Life cycle of JavaServer Faces (JSF)

In JavaServer Faces the client makes an HTTP request for the page, and the server responds with the page translated to HTML. However, the JavaServer Faces life cycle is split up into multiple phases in order to support the sophisticated UI(User Interface) component model. This model requires that component data be converted and validated, component events be handled, and component data be propagated to beans in an orderly fashion.

A JavaServer Faces page represented by a tree of UI components, called a view. During the life cycle, the JavaServer Faces implementation must build the view while considering state saved from a previous submission of the page. When the client submits a page, the JavaServer Faces implementation performs several tasks, such as validating the data input of components in the view and converting input data to types specified on the server side.

The JavaServer Faces implementation performs all these tasks as a series of steps in the JavaServer Faces request-response life cycle. The life cycle of JavaServer Faces is shown in the below figure which illustrates these steps. Continue reading “Life cycle of JavaServer Faces (JSF)”

Google Chart using JSF

We know that Google chart basically displays different statistical data on different chart types such as column chart, bar chart, line chart, pie chart etc. You can have a look at the URL https://developers.google.com/chart/ for more information.

You can integrate Google chart with any server side technology but here I will show you how to integrate Google chart using JSF. This tutorial shows step by step so that we can understand how it happens. It displays the data for area-wise top seven countries in pie chart. You can also use other charts for other purposes. In this example I have used static sample data and the actual data should come from database or other sources. You can change the source of data as per your requirements.

If you have any query please feel free to leave a comment. Continue reading “Google Chart using JSF”

JSF2 Internationalization example

This tutorial jsf2 internationalization example shows how we make an web based application in different languages. I will show here how we can switch in different languages like Bengali, Hindi, English, Dutch and French. You don’t need to change the language settings from the browser for switching to different languages. I have given user an option to choose a language in a dropdown where the langugaes are displayed in Bengali, Hindi, English, Dutch and French.

If you want you can add more languages and accordingly you need to create separate properties file for each language and configure the supported-locale in faces-config.xml file.

This application shows title, welcome message, choose language option and copyright information in Bengali, Hindi, English, Dutch and French languages. By default the selected language is English. You can also set the default language as per your choice, for that you have to configure in the LocaleSwitcher.java managed bean.

You may also like to read

Spring Boot Internationalization Example

Continue reading “JSF2 Internationalization example”

Effective pagination example in jsf 2

In this tutorial I will show how to create effective pagination example in jsf2, hibernate and mysql. There are lots of built-in API for datatable paginations like PrimeFaces, RichFaces, Openfaces, SmartFaces, ICEFaces etc. but if someone wants to create his/her own pagination then it might be useful at least for beginners.

You can create this web application in any JEE based IDE like Netbeans, Eclipse etc. Before beginning you have to have the below set of jar files in your classpath. So please download the below jar files from the respective sites and put the jars under WEB-INF/lib directory. Continue reading “Effective pagination example in jsf 2”

File upload example in JSF 2

Here we will see file upload example in jsf 2. The file upload implementation in Java based web application is very complex and we need to be dependent on Apache fileupload libraries. When we work on JSF(Java Server Faces), we have jsf pages with other inputs along with file inputs, so integration with Apache fileupload libraries make more complex or else we have to dependent on some third party file upload components like primefaces, richfaces etc.

Servlet 3.0 is part of Java EE 6 specification, hence “Part” interface and @MultiPartConfig annotation were introduced for easy way to do the file upload without any third party libraries. So any servlet 3.0 implementation servers like Tomcat 7.x, Jboss 6.x, GlassFish 3.x can get benefit of servlet 3.0 but the file upload feature is not available in JSF 2.1 and again we have to be dependent on servlet to do the file upload in JSF. Continue reading “File upload example in JSF 2”