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 private static final Logger log = Logger.getLogger(SetPropertyActionListenerTag.class.getName());
44
45 private ValueExpression target;
46
47 private ValueExpression value;
48
49 @Override
50 public int doStartTag() throws JspException
51 {
52
53 if (log.isLoggable(Level.FINE))
54 {
55 log.fine("JSF 1.2 Spec : Create a new instance of the ActionListener");
56 }
57
58 ActionListener actionListener = new SetPropertyActionListener(target, value);
59
60 UIComponentClassicTagBase tag = UIComponentClassicTagBase.getParentUIComponentClassicTagBase(pageContext);
61
62 if (tag == null)
63 {
64 throw new JspException("Could not find a " + "parent UIComponentClassicTagBase ... is this "
65 + "tag in a child of a UIComponentClassicTagBase?");
66 }
67
68 if (tag.getCreated())
69 {
70
71 UIComponent component = tag.getComponentInstance();
72
73 if (component == null)
74 {
75 throw new JspException(" Could not locate a UIComponent " + "for a UIComponentClassicTagBase w/ a "
76 + "JSP id of " + tag.getJspId());
77 }
78
79 if (!(component instanceof ActionSource))
80 {
81 throw new JspException("Component w/ id of " + component.getId()
82 + " is associated w/ a tag w/ JSP id of " + tag.getJspId() + ". This component is of type "
83 + component.getClass() + ", which is not an " + ActionSource.class);
84 }
85
86 if (log.isLoggable(Level.FINE))
87 {
88 log.fine(" ... register it with the UIComponent " + "instance associated with our most immediately "
89 + "surrounding UIComponentTagBase");
90 }
91
92 ((ActionSource)component).addActionListener(actionListener);
93
94 }
95
96 return SKIP_BODY;
97 }
98
99
100
101
102 @JSFJspAttribute(required = true,
103 className="javax.el.ValueExpression",
104 deferredValueType="java.lang.Object")
105 public ValueExpression getTarget()
106 {
107 return target;
108 }
109
110 public void setTarget(ValueExpression target)
111 {
112 this.target = target;
113 }
114
115
116
117
118
119
120 @JSFJspAttribute(required = true,
121 className="javax.el.ValueExpression",
122 deferredValueType="java.lang.Object")
123 public ValueExpression getValue()
124 {
125 return value;
126 }
127
128 public void setValue(ValueExpression value)
129 {
130 this.value = value;
131 }
132
133 @Override
134 public void release()
135 {
136 target = null;
137 value = null;
138 }
139
140 }