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