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 javax.el.ValueExpression;
22 import javax.faces.component.ActionSource;
23 import javax.faces.component.UIComponent;
24 import javax.faces.event.ActionListener;
25 import javax.faces.webapp.UIComponentClassicTagBase;
26 import javax.servlet.jsp.JspException;
27 import javax.servlet.jsp.tagext.TagSupport;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
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(
41 name="f:setPropertyActionListener",
42 bodyContent="empty")
43 public class SetPropertyActionListenerTag extends TagSupport
44 {
45
46 private static final Log log = LogFactory.getLog(SetPropertyActionListenerTag.class);
47
48 private ValueExpression target;
49
50 private ValueExpression value;
51
52 public int doStartTag() throws JspException
53 {
54
55 if(log.isDebugEnabled())
56 log.debug("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 " +
64 "parent UIComponentClassicTagBase ... is this " +
65 "tag in a child of a UIComponentClassicTagBase?");
66
67 if(tag.getCreated())
68 {
69
70 UIComponent component = tag.getComponentInstance();
71
72 if(component == null)
73 throw new JspException(" Could not locate a UIComponent " +
74 "for a UIComponentClassicTagBase w/ a " +
75 "JSP id of " + tag.getJspId());
76
77 if( ! ( component instanceof ActionSource ) )
78 throw new JspException("Component w/ id of " + component.getId()
79 + " is associated w/ a tag w/ JSP id of " + tag.getJspId()
80 + ". This component is of type " + component.getClass()
81 + ", which is not an " + ActionSource.class );
82
83 if(log.isDebugEnabled())
84 log.debug(" ... register it with the UIComponent " +
85 "instance associated with our most immediately " +
86 "surrounding UIComponentTagBase");
87
88 ((ActionSource)component).addActionListener(actionListener);
89
90 }
91
92 return SKIP_BODY;
93 }
94
95
96
97
98 @JSFJspAttribute(required=true)
99 public ValueExpression getTarget()
100 {
101 return target;
102 }
103
104 public void setTarget(ValueExpression target)
105 {
106 this.target = target;
107 }
108
109
110
111
112
113
114 @JSFJspAttribute(required=true)
115 public ValueExpression getValue()
116 {
117 return value;
118 }
119
120 public void setValue(ValueExpression value)
121 {
122 this.value = value;
123 }
124
125 public void release()
126 {
127 target = null;
128 value = null;
129 }
130
131 }