Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

JSF valueChangeListener Tag

This tag is used to add a value change listener to the component associated with the enclosing tag. Value change event is fired when the user changes the input value. This event can be fired with any component which takes user input (select or input compo


JSF Tutorials: Easy steps to learn JSF Java Server Faces (JSF) Tutorials What is JSF Mojarra? JSF Life Cycle JSF Examples JSF Tutorial For Beginners Roseindia JSF Tutorial JSF core Tag Reference JSF internationalization example Tomahawk selectOneCountry tag RCFaces About Hibernate, Spring and JSF Integration Tutorial Creating Login Page In JSF using NetBeans JSF Hello World Declaring the Bean class in the faces-config.xml file Creating a Web Application with the JSF Framework Binding the Form Elements With the Bean Properties Adding Navigation in JSF Application Binding Component Instance to a Bean Property Tomahawk validateEqual tag Tomahawk validateEmail tag Tomahawk validateCreditCard tag Tomahawk selectOneListbox tag Tomahawk selectManyListbox tag Tomahawk selectManyCheckbox tag Tomahawk selectBooleanCheckbox tag Tomahawk saveState tag Tomahawk popup tag Tomahawk inputCalendar tag Tomahawk htmlTag tag Tomahawk graphicImage tag Tomahawk documentHead tag Tomahawk documentBody tag Tomahawk document tag Tomahawk column tag DataBase Connectivity with MySql in Visual Web JSF Application Using Net Beans IDE Retrieve Image in JSF From MySQL Table Using NetBeans IDE JSF Training Java Sever Faces 1.2 - JSF 1.2 Display Data from Database in JSF Application Business Objects of Business Logic tier Setup MySQL Database Working with Database through JDBC Working with JavaScript & CSS Referencing a Localized Message Referencing Resource Bundle from a Page Binding Component Value to an Implicit Object Phase Listener Value Change Event Listener Action Event Listener

JSF valueChangeListener Tag


This tag is used to add a value change listener to the component associated with the enclosing tag. Value change event is fired when the user changes the input value. This event can be fired with any component which takes user input (select or input components). The class which is registered with the component implements ValueChangeListener interface and implements the method processValueChange(). We write our logic of action in this method. One thing that we have to take care is that we have to use onChange event of java script which submits the form when input is changed. If we will not do this then we will have to submit the form manually. This illustration will explain you how to go ahead.

Code Description :

<%@ page contentType="text/html" %>
<%@ taglib uri="" prefix="h" %>
<%@ taglib uri="" prefix="f" %>

<h:selectOneMenu id="som" value="#{MyBean.som}" title="select any one in this menu" onchange="submit()">
<f:selectItem id="si1" itemLabel="Thums Up" itemValue="11" />
<f:selectItem id="si2" itemLabel="Limca" itemValue="22" />
<f:selectItem id="si3" itemLabel="Pepsi" itemValue="33" />
<f:selectItem id="si4" itemLabel="Sprite" itemValue="44" />
<f:selectItem id="si5" itemLabel="Frooti" itemValue="55" />
<f:selectItem id="si6" itemLabel="Coca-Cola" itemValue="66" />
<f:valueChangeListener type="roseindia.MyBean" />
</f:view> :

package roseindia;

import java.util.*;
import javax.swing.*;
import javax.faces.event.*;

public class MyBean implements ActionListener,ValueChangeListener{
String som = "";
private Date today = new Date();
public void processAction(ActionEvent e){

public void processValueChange(ValueChangeEvent ce){
JOptionPane.showMessageDialog(null, ce.getSource());

public String getSom(){
return som;

public void setSom(String som){
this.som = som;

public Date getToday(){
return today;

public void setToday(Date today) { = today;

Rendered Output : This is the first page that appears to the user. 

When the user changes the current value in the menu then the value change listener is activated and gives its output according to the method processValueChange(). Here, in this example, a message dialog is open and message is shown.  

Html Source Code :

<form id="_id0" method="post" action="/f-tags/pages/valueChangeListener/valueChangeListener.jsf" enctype="application/x-www-form-urlencoded">
<select id="_id0:som" name="_id0:som" size="1" onchange="submit()" title="select any one in this menu">
<option value="11">Thums Up</option>
<option value="22">Limca</option>
<option value="33">Pepsi</option>
<option value="44">Sprite</option>
<option value="55">Frooti</option>
<option value="66">Coca-Cola</option>
<input type="hidden" name="_id0" value="_id0" /></form>

This tag contains one attribute :

type : This attribute is used to specify the fully qualified  name of the class which has implemented valueChangeListener interface and implemented processValueChange() method.


Share on Google+Share on Google+

JSF valueChangeListener Tag

Posted on: February 23, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: JSF valueChangeListener Tag   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
June 14, 2012

Fantastic!I'm currently exiineercpng the ClassCastException issue you mentioned, but I'm using a different approach. To take your example, I want a drop-down list of all Departments, plus an additional item in the list, All Departments , that should set my entity's department property to null. Do you have an idea how to do this? I've registered a custom PropertyEditor for the bean's property path and requiredType, but I still receive the error. Here's what I'm doing so far (the allDepartments var is a list of Department beans):<form:select path= department ><option value= "><All Departments></option><c:forEach items= ${allDepartments} var= d ><form:option value= ${ }${} >${d.shortDescription}</form:option></c:forEach></form:select>