Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
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 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="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:view>
<html>
<body>
<h:form>
<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" />
</h:selectOneMenu>
</h:form>
</body>
</html>
</f:view>

MyBean.java :

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){
JOptionPane.showMessageDialog(null,"Hi");
}

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) {
this.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 :

<html>
<body>
<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>
</select>
<input type="hidden" name="_id0" value="_id0" /></form>
</body>
</html>

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.

                          

» View all related tutorials
Related Tags: c com memory server dynamic tree components core component tag name this node oo ibm create root like for example

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

I want to fetch data for 2nd selectonemenu box which is disabled initially when the value for 1st selectonemenu box is changed, provided both the selectonemenu boxes are in the same page.

plz guide me for this as im not so clear of jsf lifecycle and rendering process.

Posted by sugavel on Tuesday, 04.29.08 @ 17:23pm | #58122

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.