1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package javax.faces.webapp; |
20 | |
|
21 | |
import javax.faces.application.Application; |
22 | |
import javax.faces.component.UIComponent; |
23 | |
import javax.faces.context.FacesContext; |
24 | |
import javax.faces.el.ValueBinding; |
25 | |
import javax.servlet.jsp.JspException; |
26 | |
import javax.servlet.jsp.PageContext; |
27 | |
import javax.servlet.jsp.tagext.Tag; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public abstract class UIComponentTag extends UIComponentClassicTagBase |
43 | |
{ |
44 | |
|
45 | |
|
46 | 0 | private String _binding = null; |
47 | 0 | private String _rendered = null; |
48 | |
|
49 | 0 | private Boolean _suppressed = null; |
50 | |
|
51 | |
public UIComponentTag() |
52 | 0 | { |
53 | |
|
54 | 0 | } |
55 | |
|
56 | |
@Override |
57 | |
public void release() |
58 | |
{ |
59 | 0 | super.release(); |
60 | |
|
61 | 0 | _binding = null; |
62 | 0 | _rendered = null; |
63 | 0 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public void setBinding(String binding) throws JspException |
69 | |
{ |
70 | 0 | if (!isValueReference(binding)) |
71 | |
{ |
72 | 0 | throw new IllegalArgumentException("not a valid binding: " + binding); |
73 | |
} |
74 | 0 | _binding = binding; |
75 | 0 | } |
76 | |
|
77 | |
|
78 | |
public void setRendered(String rendered) |
79 | |
{ |
80 | 0 | _rendered = rendered; |
81 | 0 | } |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public static UIComponentTag getParentUIComponentTag(PageContext pageContext) |
89 | |
{ |
90 | 0 | UIComponentClassicTagBase parentTag = getParentUIComponentClassicTagBase(pageContext); |
91 | |
|
92 | 0 | return parentTag instanceof UIComponentTag ? (UIComponentTag)parentTag : new UIComponentTagWrapper(parentTag); |
93 | |
|
94 | |
} |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
public static boolean isValueReference(String value) |
103 | |
{ |
104 | 0 | if (value == null) |
105 | |
{ |
106 | 0 | throw new NullPointerException("value"); |
107 | |
} |
108 | |
|
109 | 0 | int start = value.indexOf("#{"); |
110 | 0 | if (start < 0) |
111 | |
{ |
112 | 0 | return false; |
113 | |
} |
114 | |
|
115 | 0 | int end = value.lastIndexOf('}'); |
116 | 0 | return (end >= 0 && start < end); |
117 | |
} |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
@Override |
127 | |
protected UIComponent createComponent(FacesContext context, String id) |
128 | |
{ |
129 | 0 | String componentType = getComponentType(); |
130 | 0 | if (componentType == null) |
131 | |
{ |
132 | 0 | throw new NullPointerException("componentType"); |
133 | |
} |
134 | |
|
135 | 0 | if (_binding != null) |
136 | |
{ |
137 | 0 | Application application = context.getApplication(); |
138 | 0 | ValueBinding componentBinding = application.createValueBinding(_binding); |
139 | 0 | UIComponent component = application.createComponent(componentBinding, context, componentType); |
140 | |
|
141 | 0 | component.setId(id); |
142 | 0 | component.setValueBinding("binding", componentBinding); |
143 | 0 | setProperties(component); |
144 | |
|
145 | 0 | return component; |
146 | |
} |
147 | |
|
148 | 0 | UIComponent component = context.getApplication().createComponent(componentType); |
149 | 0 | component.setId(id); |
150 | 0 | setProperties(component); |
151 | |
|
152 | 0 | return component; |
153 | |
|
154 | |
} |
155 | |
|
156 | |
private boolean isFacet() |
157 | |
{ |
158 | 0 | return getParent() != null && getParent() instanceof FacetTag; |
159 | |
} |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
protected boolean isSuppressed() |
166 | |
{ |
167 | 0 | if (_suppressed == null) |
168 | |
{ |
169 | |
|
170 | |
|
171 | |
|
172 | 0 | if (isFacet()) |
173 | |
{ |
174 | |
|
175 | 0 | _suppressed = Boolean.TRUE; |
176 | 0 | return true; |
177 | |
} |
178 | |
|
179 | 0 | UIComponent component = getComponentInstance(); |
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | 0 | UIComponent parent = component.getParent(); |
186 | 0 | while (parent != null) |
187 | |
{ |
188 | 0 | if (parent.getRendersChildren()) |
189 | |
{ |
190 | |
|
191 | 0 | _suppressed = Boolean.TRUE; |
192 | 0 | return true; |
193 | |
} |
194 | 0 | parent = parent.getParent(); |
195 | |
} |
196 | |
|
197 | |
|
198 | 0 | while (component != null) |
199 | |
{ |
200 | 0 | if (!component.isRendered()) |
201 | |
{ |
202 | |
|
203 | 0 | _suppressed = Boolean.TRUE; |
204 | 0 | return true; |
205 | |
} |
206 | 0 | component = component.getParent(); |
207 | |
} |
208 | |
|
209 | |
|
210 | 0 | _suppressed = Boolean.FALSE; |
211 | |
} |
212 | 0 | return _suppressed.booleanValue(); |
213 | |
} |
214 | |
|
215 | |
@Override |
216 | |
protected void setProperties(UIComponent component) |
217 | |
{ |
218 | 0 | if (getRendererType() != null) |
219 | |
{ |
220 | 0 | component.setRendererType(getRendererType()); |
221 | |
} |
222 | |
|
223 | 0 | if (_rendered != null) |
224 | |
{ |
225 | 0 | if (isValueReference(_rendered)) |
226 | |
{ |
227 | 0 | ValueBinding vb = getFacesContext().getApplication().createValueBinding(_rendered); |
228 | 0 | component.setValueBinding("rendered", vb); |
229 | 0 | } |
230 | |
else |
231 | |
{ |
232 | 0 | boolean b = Boolean.valueOf(_rendered).booleanValue(); |
233 | 0 | component.setRendered(b); |
234 | |
} |
235 | |
} |
236 | 0 | } |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
private static class UIComponentTagWrapper extends UIComponentTag |
245 | |
{ |
246 | |
private UIComponentClassicTagBase target; |
247 | |
|
248 | |
public UIComponentTagWrapper(UIComponentClassicTagBase classicTag) |
249 | 0 | { |
250 | 0 | target = classicTag; |
251 | 0 | } |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
@Override |
258 | |
public String getComponentType() |
259 | |
{ |
260 | 0 | return target.getComponentType(); |
261 | |
} |
262 | |
|
263 | |
@Override |
264 | |
public String getRendererType() |
265 | |
{ |
266 | 0 | return target.getRendererType(); |
267 | |
} |
268 | |
|
269 | |
@Override |
270 | |
public boolean getCreated() |
271 | |
{ |
272 | 0 | return target.getCreated(); |
273 | |
} |
274 | |
|
275 | |
@Override |
276 | |
public String getId() |
277 | |
{ |
278 | 0 | return target.getId(); |
279 | |
} |
280 | |
|
281 | |
@Override |
282 | |
public UIComponent getComponentInstance() |
283 | |
{ |
284 | 0 | return target.getComponentInstance(); |
285 | |
} |
286 | |
|
287 | |
@Override |
288 | |
public Tag getParent() |
289 | |
{ |
290 | 0 | return target.getParent(); |
291 | |
} |
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
@Override |
298 | |
public void release() |
299 | |
{ |
300 | 0 | throw new UnsupportedOperationException(); |
301 | |
} |
302 | |
|
303 | |
@Override |
304 | |
public void setBinding(String binding) throws JspException |
305 | |
{ |
306 | 0 | throw new UnsupportedOperationException(); |
307 | |
} |
308 | |
|
309 | |
@Override |
310 | |
public void setId(String id) |
311 | |
{ |
312 | 0 | throw new UnsupportedOperationException(); |
313 | |
} |
314 | |
|
315 | |
@Override |
316 | |
public void setRendered(String state) |
317 | |
{ |
318 | 0 | throw new UnsupportedOperationException(); |
319 | |
} |
320 | |
|
321 | |
@Override |
322 | |
protected UIComponent createComponent(FacesContext context, String newId) |
323 | |
{ |
324 | 0 | throw new UnsupportedOperationException(); |
325 | |
} |
326 | |
|
327 | |
@Override |
328 | |
public void setPageContext(PageContext context) |
329 | |
{ |
330 | 0 | throw new UnsupportedOperationException(); |
331 | |
} |
332 | |
|
333 | |
@Override |
334 | |
public void setParent(Tag parent) |
335 | |
{ |
336 | 0 | throw new UnsupportedOperationException(); |
337 | |
} |
338 | |
|
339 | |
@Override |
340 | |
protected UIComponent findComponent(FacesContext context) throws JspException |
341 | |
{ |
342 | 0 | throw new UnsupportedOperationException(); |
343 | |
} |
344 | |
|
345 | |
@Override |
346 | |
protected FacesContext getFacesContext() |
347 | |
{ |
348 | 0 | throw new UnsupportedOperationException(); |
349 | |
} |
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
} |
356 | |
|
357 | |
@Override |
358 | |
protected boolean hasBinding() |
359 | |
{ |
360 | 0 | return _binding != null; |
361 | |
} |
362 | |
} |