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