JavaServer Faces (JSF) - JSF Event Handling - JSF valueChangeListener - JavaServer Faces (JSF)

What is JSF valueChangeListener?

When the user interacts with input components, such as h:inputText or h:selectOneMenu, the JSF fires a valueChangeEvent, which can be handled in two ways.

S.No
Technique & Description
1
Method Binding
Pass the name of the managed bean method invalueChangeListenerattribute of UI Component.
2
ValueChangeListener
Implement ValueChangeListener interface and pass the implementation class name tovalueChangeListenerattribute of UI Component.

Method Binding

Define a method
Use the above method

ValueChangeListener

Implement ValueChangeListener
Use listener method

Example Application

A test JSF application is created to test the valueChangeListener in JSF.

Step
Description
1
Create a project with a namehelloworldunder a packagecom.wisdomjobs.testas explained in theJSF - First Applicationchapter.
2
ModifyUserData.javafile as explained below.
3
CreateLocaleChangeListener.javafile under a packagecom.wisdomjobs.test. Modify it as explained below.
4
Modifyhome.xhtmlas explained below. Keep the rest of the files unchanged.
5
Compile and run the application to make sure the business logic is working as per the requirements.
6
Finally, build the application in the form of war file and deploy it in Apache Tomcat Webserver.
7
Launch your web application using appropriate URL as explained below in the last step.

UserData.java

LocaleChangeListener.java

home.xhtml

Once all the changes are done, the application is compiled and run as in JSF – Create Application chapter. On successful creation of the application, the result appears as:

JSF valueChangeListener

Select locale and the result appears as:

JSF valueChangeListener Select Locale

home.xhtml is modified in the deployed directory where the application is deployed. The rest of the files are kept unchanged.

home.xhtml

Once all the changes are done, the page is refreshed in the browser. On successful creation of the application, the result appears as:

JSF valueChangeListener Interface

Select locale and the result appears as:

JSF valueChangeListener Interface Result

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JavaServer Faces (JSF) Topics