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