1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.taglib.core;
20
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23
24 import javax.el.ValueExpression;
25 import javax.faces.component.ActionSource;
26 import javax.faces.component.UIComponent;
27 import javax.faces.event.ActionListener;
28 import javax.faces.webapp.UIComponentClassicTagBase;
29 import javax.servlet.jsp.JspException;
30 import javax.servlet.jsp.tagext.TagSupport;
31
32 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspAttribute;
33 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspTag;
34 import org.apache.myfaces.event.SetPropertyActionListener;
35
36
37
38
39
40 @JSFJspTag(name = "f:setPropertyActionListener", bodyContent = "empty")
41 public class SetPropertyActionListenerTag extends TagSupport
42 {
43
44
45 private static final Logger log = Logger.getLogger(SetPropertyActionListenerTag.class.getName());
46
47 private ValueExpression target;
48
49 private ValueExpression value;
50
51 @Override
52 public int doStartTag() throws JspException
53 {
54
55 if (log.isLoggable(Level.FINE))
56 log.fine("JSF 1.2 Spec : Create a new instance of the ActionListener");
57
58 ActionListener actionListener = new SetPropertyActionListener(target, value);
59
60 UIComponentClassicTagBase tag = UIComponentClassicTagBase.getParentUIComponentClassicTagBase(pageContext);
61
62 if (tag == null)
63 throw new JspException("Could not find a " + "parent UIComponentClassicTagBase ... is this "
64 + "tag in a child of a UIComponentClassicTagBase?");
65
66 if (tag.getCreated())
67 {
68
69 UIComponent component = tag.getComponentInstance();
70
71 if (component == null)
72 throw new JspException(" Could not locate a UIComponent " + "for a UIComponentClassicTagBase w/ a "
73 + "JSP id of " + tag.getJspId());
74
75 if (!(component instanceof ActionSource))
76 throw new JspException("Component w/ id of " + component.getId()
77 + " is associated w/ a tag w/ JSP id of " + tag.getJspId() + ". This component is of type "
78 + component.getClass() + ", which is not an " + ActionSource.class);
79
80 if (log.isLoggable(Level.FINE))
81 log.fine(" ... register it with the UIComponent " + "instance associated with our most immediately "
82 + "surrounding UIComponentTagBase");
83
84 ((ActionSource)component).addActionListener(actionListener);
85
86 }
87
88 return SKIP_BODY;
89 }
90
91
92
93
94 @JSFJspAttribute(required = true,
95 className="javax.el.ValueExpression",
96 deferredValueType="java.lang.Object")
97 public ValueExpression getTarget()
98 {
99 return target;
100 }
101
102 public void setTarget(ValueExpression target)
103 {
104 this.target = target;
105 }
106
107
108
109
110
111
112 @JSFJspAttribute(required = true,
113 className="javax.el.ValueExpression",
114 deferredValueType="java.lang.Object")
115 public ValueExpression getValue()
116 {
117 return value;
118 }
119
120 public void setValue(ValueExpression value)
121 {
122 this.value = value;
123 }
124
125 @Override
126 public void release()
127 {
128 target = null;
129 value = null;
130 }
131
132 }