1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.view.facelets.tag.ui; |
20 | |
|
21 | |
import java.io.IOException; |
22 | |
|
23 | |
import javax.el.ELException; |
24 | |
import javax.el.ValueExpression; |
25 | |
import javax.faces.FacesException; |
26 | |
import javax.faces.component.UIComponent; |
27 | |
import javax.faces.view.facelets.FaceletContext; |
28 | |
import javax.faces.view.facelets.FaceletException; |
29 | |
import javax.faces.view.facelets.TagAttribute; |
30 | |
import javax.faces.view.facelets.TagConfig; |
31 | |
import javax.faces.view.facelets.TagHandler; |
32 | |
|
33 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletAttribute; |
34 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag; |
35 | |
import org.apache.myfaces.util.ExternalSpecifications; |
36 | |
import org.apache.myfaces.view.facelets.AbstractFaceletContext; |
37 | |
import org.apache.myfaces.view.facelets.ELExpressionCacheMode; |
38 | |
import org.apache.myfaces.view.facelets.el.FaceletStateValueExpression; |
39 | |
import org.apache.myfaces.view.facelets.el.FaceletStateValueExpressionUEL; |
40 | |
import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport; |
41 | |
import org.apache.myfaces.view.facelets.tag.jsf.FaceletState; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
@JSFFaceletTag(name="ui:param") |
48 | |
public class ParamHandler extends TagHandler |
49 | |
{ |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
@JSFFaceletAttribute( |
55 | |
className="javax.el.ValueExpression", |
56 | |
deferredValueType="java.lang.String", |
57 | |
required=true) |
58 | |
private final TagAttribute name; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
@JSFFaceletAttribute( |
64 | |
className="javax.el.ValueExpression", |
65 | |
deferredValueType="java.lang.String", |
66 | |
required=true) |
67 | |
private final TagAttribute value; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public ParamHandler(TagConfig config) |
73 | |
{ |
74 | 0 | super(config); |
75 | 0 | this.name = this.getRequiredAttribute("name"); |
76 | 0 | this.value = this.getRequiredAttribute("value"); |
77 | 0 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, |
86 | |
ELException |
87 | |
{ |
88 | 0 | String nameStr = getName(ctx); |
89 | 0 | ValueExpression valueVE = getValue(ctx); |
90 | |
|
91 | 0 | apply(ctx, parent, nameStr, valueVE); |
92 | 0 | } |
93 | |
|
94 | |
public void apply(FaceletContext ctx, UIComponent parent, String nameStr, ValueExpression valueVE) |
95 | |
throws IOException, FacesException, FaceletException, ELException |
96 | |
{ |
97 | 0 | AbstractFaceletContext actx = ((AbstractFaceletContext) ctx); |
98 | 0 | actx.getTemplateContext().setParameter(nameStr, valueVE); |
99 | |
|
100 | 0 | if (actx.getTemplateContext().isAllowCacheELExpressions()) |
101 | |
{ |
102 | 0 | if (ELExpressionCacheMode.strict.equals(actx.getELExpressionCacheMode()) || |
103 | |
ELExpressionCacheMode.allowCset.equals(actx.getELExpressionCacheMode())) |
104 | |
{ |
105 | 0 | actx.getTemplateContext().setAllowCacheELExpressions(false); |
106 | |
} |
107 | |
} |
108 | 0 | } |
109 | |
|
110 | |
public void apply(FaceletContext ctx, UIComponent parent, String nameStr, ValueExpression valueVE, |
111 | |
String uniqueId) |
112 | |
throws IOException, FacesException, FaceletException, ELException |
113 | |
{ |
114 | 0 | AbstractFaceletContext actx = ((AbstractFaceletContext) ctx); |
115 | 0 | if (ELExpressionCacheMode.alwaysRecompile.equals(actx.getELExpressionCacheMode())) |
116 | |
{ |
117 | 0 | FaceletState faceletState = ComponentSupport.getFaceletState(ctx, parent, true); |
118 | 0 | faceletState.putBinding(uniqueId, nameStr, valueVE); |
119 | |
ValueExpression ve; |
120 | 0 | if (ExternalSpecifications.isUnifiedELAvailable()) |
121 | |
{ |
122 | 0 | ve = new FaceletStateValueExpressionUEL(uniqueId, nameStr); |
123 | |
} |
124 | |
else |
125 | |
{ |
126 | 0 | ve = new FaceletStateValueExpression(uniqueId, nameStr); |
127 | |
} |
128 | 0 | actx.getTemplateContext().setParameter(nameStr, ve); |
129 | 0 | } |
130 | |
else |
131 | |
{ |
132 | 0 | actx.getTemplateContext().setParameter(nameStr, valueVE); |
133 | |
} |
134 | |
|
135 | 0 | if (actx.getTemplateContext().isAllowCacheELExpressions()) |
136 | |
{ |
137 | 0 | if (ELExpressionCacheMode.strict.equals(actx.getELExpressionCacheMode()) || |
138 | |
ELExpressionCacheMode.allowCset.equals(actx.getELExpressionCacheMode())) |
139 | |
{ |
140 | 0 | actx.getTemplateContext().setAllowCacheELExpressions(false); |
141 | |
} |
142 | |
} |
143 | 0 | } |
144 | |
|
145 | |
public String getName(FaceletContext ctx) |
146 | |
{ |
147 | 0 | return this.name.getValue(ctx); |
148 | |
} |
149 | |
|
150 | |
public ValueExpression getValue(FaceletContext ctx) |
151 | |
{ |
152 | 0 | return this.value.getValueExpression(ctx, Object.class); |
153 | |
} |
154 | |
} |