View Javadoc

1   /*
2    * $Id: ErrorListenerTag.java,v 1.2 2007/05/24 12:26:17 oeuillot Exp $
3    */
4   package org.rcfaces.core.internal.taglib;
5   
6   import javax.faces.FacesException;
7   import javax.faces.component.UIComponent;
8   
9   import org.apache.commons.logging.Log;
10  import org.apache.commons.logging.LogFactory;
11  import org.rcfaces.core.component.capability.IErrorEventCapability;
12  import org.rcfaces.core.event.IErrorListener;
13  
14  /**
15   * 
16   * @author Olivier Oeuillot (latest modification by $Author: oeuillot $)
17   * @version $Revision: 1.2 $ $Date: 2007/05/24 12:26:17 $
18   */
19  public class ErrorListenerTag extends AbstractListenerTag {
20      private static final String REVISION = "$Revision: 1.2 $";
21  
22      private static final long serialVersionUID = 5117953058731866439L;
23  
24      private static final Log LOG = LogFactory.getLog(ErrorListenerTag.class);
25  
26      protected void addListener(Object listener, UIComponent component) {
27          addErrorListener(listener, component);
28      }
29  
30      public static void addErrorListener(Object listener, UIComponent component) {
31  
32          if ((listener instanceof IErrorListener) == false) {
33              throw new FacesException("Listener '" + listener
34                      + "' must implement IErrorListener.");
35          }
36  
37          IErrorListener errorListener = (IErrorListener) listener;
38  
39          if ((component instanceof IErrorEventCapability) == false) {
40              LOG.error("Component '" + component.getId()
41                      + "' does not implement IErrorEventCapability.");
42              return;
43          }
44  
45          ((IErrorEventCapability) component).addErrorListener(errorListener);
46  
47          if (LOG.isDebugEnabled()) {
48              LOG.debug("Add an errorListener '" + errorListener
49                      + "' to component '" + component.getId() + "'.");
50          }
51      }
52  
53      protected String getListenerName() {
54          return "error";
55      }
56  
57  }