1
2
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.IUserEventCapability;
12 import org.rcfaces.core.event.IUserEventListener;
13
14
15
16
17
18
19 public class UserEventListenerTag extends AbstractListenerTag {
20
21 private static final String REVISION = "$Revision: 1.1 $";
22
23 private static final long serialVersionUID = -3769010939257728457L;
24
25 private static final Log LOG = LogFactory
26 .getLog(UserEventListenerTag.class);
27
28 protected void addListener(Object listener, UIComponent component) {
29 addUserEventListener(listener, component);
30 }
31
32 public static void addUserEventListener(Object listener,
33 UIComponent component) {
34
35 if ((listener instanceof IUserEventListener) == false) {
36 throw new FacesException("Listener '" + listener
37 + "' must implement IUserEventListener.");
38 }
39
40 IUserEventListener userEventListener = (IUserEventListener) listener;
41
42 if ((component instanceof IUserEventCapability) == false) {
43 LOG.error("Component '" + component.getId()
44 + "' does not implement IUserEventCapability.");
45 return;
46 }
47
48 ((IUserEventCapability) component)
49 .addUserEventListener(userEventListener);
50
51 if (LOG.isDebugEnabled()) {
52 LOG.debug("Add userEventListener '" + userEventListener
53 + "' to component '" + component.getId() + "'.");
54 }
55 }
56
57 protected String getListenerName() {
58 return "userEvent";
59 }
60
61 }