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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Action Event Listener 
 

Action Listeners can be implemented in 2 ways. If you use the first one then it will limit you to use only one listener for the component but second way permits you to include more than one event listeners.

 

Action Event Listener

                          

Action Listeners can be implemented in 2 ways. If you use the first one then it will limit you to use only one listener for the component but second way permits you to include more than one event listeners.

1. Using "actionListener" attribute of the component tag

 

 

 

 

 

<h:commandButton id="cb1" value="#{ActionBean.buttonText}" immediate="true" actionListener="#{ActionBean.processMyAction}"/>

Sample Code for processMyAction method in "ActionBean":

/*Action listener method*/

public void processMyAction(ActionEvent event){

     disable = !disable;
     System.out.println("disable: "+ disable);

     if(buttonText.equals("Disable")){
           buttonText = "Enable"; 
           System.out.println("buttonText: "+ buttonText);
     }
     else{
           buttonText = "Disable";
           System.out.println("buttonText: "+ buttonText);
     }
}

 

2. Using <f:actionListener /> tag

The ActionListener interface must be implemented to capture an ActionEvent. This interface provides processAction() method which is called when the ActionEvent for which the ActionListener is registered occurs. So processAction() method should be implemented for the action event listeners.

processAction method signature:

public void processAction(ActionEvent event) throws AbortProcessingException

For Example:(In JSP)

<h:commandLink id="France" immediate="true" value="Set Locale(France)">
            <f:actionListener type="roseindia.MyActionBean" />
</h:commandLink>

The code for MyActionBean.java:

package roseindia;

import java.util.*;
import javax.faces.event.*;
import javax.faces.context.FacesContext;

public class MyActionBean extends Object implements ActionListener {

     public void processAction(ActionEvent event) throws AbortProcessingException{         
             Map locales = null;
             locales = new HashMap();
             locales.put("America", new Locale("en", "US")); 
             locales.put("France", new Locale("fr", "FR"));

             String current = event.getComponent().getId();
             FacesContext context = FacesContext.getCurrentInstance();
             context.getViewRoot().setLocale((Locale) locales.get(current));
     }
}

Download code for all examples

                          

» View all related tutorials
Related Tags: c file ide orm text date jsf form internationalization time air button io dates format label numbers vi locale key

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 
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.