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.

The following configurations are required in order to run the application

JDK 1.8
Tomcat 8
Have maven installed and configured
JSF 2 and servlet api dependencies in pom.xml

Now we will see the below steps how to create a maven based spring project in Eclipse

First we will create service project

Step 1. Create a maven based web project in Eclipse

Go to File -> New -> Other. On popup window under Maven select Maven Project. Then click on Next. Select the workspace location – either default or browse the location. Click on Next. Now in next window select the row as highlighted from the below list of archtypes and click on Next button.


Now enter the required fields (Group Id, Artifact Id) as shown below

Group Id : com.roytuts
Artifact Id : jsf2

Step 2. Modify the pom.xml file as shown below.

Step 3. If you see JRE System Library[J2SE-1.5] then change the version by below process

Do right-click on the project and go to Build -> Configure build path, under Libraries tab click on JRE System Library[J2SE-1.5], click on Edit button and select the appropriate jdk 1.8 from the next window. Click on Finish then Ok.

Step 4. Modify generated web.xml file with below source code

Step 5. Create index.xhtml file with the below source code

We have a command button in the index.xhtml page so when this page appears we can simply click on the button to go to the registration page as shown below in the next step.

Step 6. Create register.xhtml page with below source code

We have two command buttons in this register page – one(Register button) for registering yourself to the system and another(Cancel button) for getting back to the index page or home page. Now suppose you have entered something or you are trying to submit the form without filling anything in the form, so you will get validation error(s) and now you thought you want to get back to the index or home page but you will not be able to go back to the index or home page because of validation error(s). So in this situation you have to correct all errors then only you can go back to the home page.

This happens because even though you are just clicking the Cancel button with an empty form, it is still handled as a “postback” request, meaning that the JSF lifecycle commences to process an assumed incoming set of name-value pairs from the form. But since the form is empty, validation errors are encountered before the navigation handler can process the “cancel” action event and a response of the same page is rendered back to the client.

jsf immediate example

Therefore the solution is to add “immediate” attribute to the Cancel button as shown below.

An immediate attribute is added to the Cancel button (or any UICommand component) and its value is set to “true,” it will allow the lifecycle to immediately bypass any validation and navigate back to the main.xhtml page. In general, setting the immediate attribute to “true” on a UICommand component triggers an action event to be fired immediately during the Apply Request Values phase before the Process Validations phase, so no validation errors are encountered.

Step 7. Create JSF managed bean for register.xhtml page with below source code

Step 8. Now run the application.

Thanks for reading.


Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.