ValueChangeListener example in JSF 2

This tutorial shows how to use ValueChangeListener to create dependent dropdown in JSF 2 and MySQL. I have used here JSF valueChangeListener which fires value change event when select option gets change. Any component that receives user input, such as one of the HTML select or text input components, can publish value change events.
Prerequisites

MySQL database
JSF 2.2
Tomcat 7
JDK 1.6_43
jar files
valuechangelistener example in jsf

At the end of this example you will be able to see this output in the browser:

When the index.jsf file gets executed

valuechangelistener example in jsf
When you select the parent category and for this category if there is any sub-category
valuechangelistener example in jsf
When you select sub-category and press the submit button
valuechangelistener example in jsf
Now look at the below source codes.

Create MySQL database tables

Table – category

 

Insert some data

 

Table – tutorial

 

Insert some data

 

Now we will look into the JSF part Deployment descriptor – web.xml

 

Look at the view file – index.xhtml

 

JSF managed bean – ComboboxMBean.java. I am not going to use faces-config.xml file so I have used annotation based configuration for managed bean.

 

Model – Category.java

 

Constant declarations – Constants.java

 

Database helper class for database related common functionality

 

QueryHelper for database query

 

Thanks for your reading. Please do not forget to leave a comment. Comment helps to improve.

Soumitra

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.