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.composite;
20
21 import javax.el.ExpressionFactory;
22 import javax.el.MethodExpression;
23 import javax.faces.component.UICommand;
24 import javax.faces.component.UIComponent;
25 import javax.faces.component.UINamingContainer;
26 import javax.faces.component.UIViewRoot;
27
28 import org.apache.myfaces.config.RuntimeConfig;
29 import org.apache.myfaces.test.mock.MockExternalContext;
30 import org.apache.myfaces.view.facelets.FaceletTestCase;
31 import org.junit.Assert;
32 import org.junit.Test;
33
34 public class CompositeComponentMethodExpressionTestCase extends FaceletTestCase
35 {
36 @Override
37 protected void setupComponents() throws Exception
38 {
39 super.setupComponents();
40 application.addComponent(CompositeTestComponent.class.getName(),
41 CompositeTestComponent.class.getName());
42 application.addComponent(SimpleComponent.class.getName(), SimpleComponent.class.getName());
43 }
44
45 @Override
46 protected void setUpServletObjects() throws Exception
47 {
48 super.setUpServletObjects();
49 servletContext.addInitParameter("javax.faces.FACELETS_LIBRARIES", "/test-facelet.taglib.xml");
50 }
51
52 @Override
53 protected ExpressionFactory createExpressionFactory()
54 {
55 return new org.apache.el.ExpressionFactoryImpl();
56 }
57
58 @Test
59 public void testSimpleMethodExpressionTarget() throws Exception
60 {
61 MockAttributeBean bean = new MockAttributeBean();
62
63 facesContext.getExternalContext().getRequestMap().put("bean",
64 bean);
65
66 UIViewRoot root = facesContext.getViewRoot();
67 vdl.buildView(facesContext, root, "testSimpleAttributeMethodExpressionTarget.xhtml");
68
69
70 UIComponent panelGroup1 = root.findComponent("testGroup1");
71 Assert.assertNotNull(panelGroup1);
72 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
73 Assert.assertNotNull(compositeComponent);
74 SimpleComponent testComponent = (SimpleComponent) compositeComponent.findComponent("testComponent");
75 Assert.assertNotNull(testComponent);
76 Assert.assertNotNull(testComponent.getCustomMethod());
77 Assert.assertEquals("somethingFunny"+"x", testComponent.getCustomMethod().invoke(facesContext.getELContext(), new Object[]{"x"}));
78 }
79
80 @Test
81 public void testCompositeMethodExpressionTarget() throws Exception
82 {
83 MockAttributeBean bean = new MockAttributeBean();
84
85 facesContext.getExternalContext().getRequestMap().put("bean",
86 bean);
87
88 UIViewRoot root = facesContext.getViewRoot();
89 vdl.buildView(facesContext, root, "testCompositeAttributeMethodExpressionTarget.xhtml");
90
91
92 UIComponent panelGroup1 = root.findComponent("testGroup1");
93 Assert.assertNotNull(panelGroup1);
94 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
95 Assert.assertNotNull(compositeComponent);
96
97 UINamingContainer compositeComponent2 = (UINamingContainer) compositeComponent.findComponent("simpleAttributeMethodExpressionTarget");
98 Assert.assertNotNull(compositeComponent2);
99 SimpleComponent testComponent = (SimpleComponent) compositeComponent2.findComponent("testComponent");
100 Assert.assertNotNull(testComponent);
101 Assert.assertNotNull(testComponent.getCustomMethod());
102 Assert.assertEquals("somethingFunny"+"x", testComponent.getCustomMethod().invoke(facesContext.getELContext(), new Object[]{"x"}));
103 }
104
105 @Test
106 public void testSimpleMethodExpressionNoTarget() throws Exception
107 {
108 MockAttributeBean bean = new MockAttributeBean();
109
110 facesContext.getExternalContext().getRequestMap().put("bean",
111 bean);
112
113 UIViewRoot root = facesContext.getViewRoot();
114 vdl.buildView(facesContext, root, "testSimpleAttributeMethodExpressionNoTarget.xhtml");
115
116
117 UIComponent panelGroup1 = root.findComponent("testGroup1");
118 Assert.assertNotNull(panelGroup1);
119 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
120 Assert.assertNotNull(compositeComponent);
121
122 SimpleComponent testComponentNoTarget = (SimpleComponent) compositeComponent.findComponent("testComponentNoTarget");
123 Assert.assertNotNull(testComponentNoTarget);
124 Assert.assertNotNull(testComponentNoTarget.getCustomMethod());
125
126 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
127 Assert.assertEquals("somethingFunny"+"x", testComponentNoTarget.getCustomMethod().invoke(facesContext.getELContext(), new Object[]{"x"}));
128 compositeComponent.popComponentFromEL(facesContext);
129 }
130
131 @Test
132 public void testCompositeMethodExpressionNoTarget() throws Exception
133 {
134 MockAttributeBean bean = new MockAttributeBean();
135
136 facesContext.getExternalContext().getRequestMap().put("bean",
137 bean);
138
139 UIViewRoot root = facesContext.getViewRoot();
140 vdl.buildView(facesContext, root, "testCompositeAttributeMethodExpressionNoTarget.xhtml");
141
142
143 UIComponent panelGroup1 = root.findComponent("testGroup1");
144 Assert.assertNotNull(panelGroup1);
145 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
146 Assert.assertNotNull(compositeComponent);
147
148 UINamingContainer compositeComponent3 = (UINamingContainer) compositeComponent.findComponent("simpleAttributeMethodExpressionNoTarget");
149 Assert.assertNotNull(compositeComponent3);
150 SimpleComponent testComponentNoTarget3 = (SimpleComponent) compositeComponent3.findComponent("testComponentNoTarget");
151 Assert.assertNotNull(testComponentNoTarget3);
152 Assert.assertNotNull(testComponentNoTarget3.getCustomMethod());
153 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
154 compositeComponent.pushComponentToEL(facesContext, compositeComponent3);
155 Assert.assertEquals("somethingFunny"+"x", testComponentNoTarget3.getCustomMethod().invoke(facesContext.getELContext(), new Object[]{"x"}));
156 compositeComponent3.popComponentFromEL(facesContext);
157 compositeComponent.popComponentFromEL(facesContext);
158 }
159
160 @Test
161 public void testCompositeMethodExpressionNoTarget2() throws Exception
162 {
163 MockAttributeBean bean = new MockAttributeBean();
164
165 facesContext.getExternalContext().getRequestMap().put("bean",
166 bean);
167
168 UIViewRoot root = facesContext.getViewRoot();
169 vdl.buildView(facesContext, root, "testCompositeAttributeMethodExpressionNoTarget2.xhtml");
170
171
172 UIComponent panelGroup1 = root.findComponent("testGroup1");
173 Assert.assertNotNull(panelGroup1);
174 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
175 Assert.assertNotNull(compositeComponent);
176
177 UINamingContainer compositeComponent2 = (UINamingContainer) compositeComponent.findComponent("compositeAttributeMethodExpressionNoTarget");
178 Assert.assertNotNull(compositeComponent2);
179 UINamingContainer compositeComponent3 = (UINamingContainer) compositeComponent2.findComponent("simpleAttributeMethodExpressionNoTarget");
180 Assert.assertNotNull(compositeComponent3);
181 SimpleComponent testComponentNoTarget3 = (SimpleComponent) compositeComponent3.findComponent("testComponentNoTarget");
182 Assert.assertNotNull(testComponentNoTarget3);
183 Assert.assertNotNull(testComponentNoTarget3.getCustomMethod());
184 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
185 compositeComponent.pushComponentToEL(facesContext, compositeComponent3);
186 Assert.assertEquals("somethingFunny"+"x", testComponentNoTarget3.getCustomMethod().invoke(facesContext.getELContext(), new Object[]{"x"}));
187 compositeComponent3.popComponentFromEL(facesContext);
188 compositeComponent.popComponentFromEL(facesContext);
189 }
190
191
192 @Test
193 public void testSimpleMethodExpressionTarget2() throws Exception
194 {
195 MockAttributeBean bean = new MockAttributeBean();
196
197 facesContext.getExternalContext().getRequestMap().put("bean",
198 bean);
199
200 UIViewRoot root = facesContext.getViewRoot();
201 vdl.buildView(facesContext, root, "testSimpleAttributeMethodExpressionTarget2.xhtml");
202
203
204 UIComponent panelGroup1 = root.findComponent("testGroup1");
205 Assert.assertNotNull(panelGroup1);
206 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
207 Assert.assertNotNull(compositeComponent);
208 SimpleComponent testComponent = (SimpleComponent) compositeComponent.findComponent("testComponent");
209 Assert.assertNotNull(testComponent);
210 Assert.assertNotNull(testComponent.getCustomMethod());
211 Assert.assertEquals("somethingFunny"+"x", testComponent.getCustomMethod().invoke(facesContext.getELContext(), new Object[]{"x"}));
212
213 SimpleComponent testComponentNoTarget = (SimpleComponent) compositeComponent.findComponent("testComponentNoTarget");
214 Assert.assertNotNull(testComponentNoTarget);
215 Assert.assertNotNull(testComponentNoTarget.getCustomMethod());
216 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
217 Assert.assertEquals("somethingFunny"+"x", testComponentNoTarget.getCustomMethod().invoke(facesContext.getELContext(), new Object[]{"x"}));
218 compositeComponent.popComponentFromEL(facesContext);
219 }
220
221 @Test
222 public void testCompositeMethodExpressionTarget2() throws Exception
223 {
224 MockAttributeBean bean = new MockAttributeBean();
225
226 facesContext.getExternalContext().getRequestMap().put("bean",
227 bean);
228
229 UIViewRoot root = facesContext.getViewRoot();
230 vdl.buildView(facesContext, root, "testCompositeAttributeMethodExpressionTarget2.xhtml");
231
232
233 UIComponent panelGroup1 = root.findComponent("testGroup1");
234 Assert.assertNotNull(panelGroup1);
235 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
236 Assert.assertNotNull(compositeComponent);
237
238 UINamingContainer compositeComponent2 = (UINamingContainer) compositeComponent.findComponent("simpleAttributeMethodExpressionTarget");
239 Assert.assertNotNull(compositeComponent2);
240 SimpleComponent testComponent = (SimpleComponent) compositeComponent2.findComponent("testComponent");
241 Assert.assertNotNull(testComponent);
242 Assert.assertNotNull(testComponent.getCustomMethod());
243 Assert.assertEquals("somethingFunny"+"x", testComponent.getCustomMethod().invoke(facesContext.getELContext(), new Object[]{"x"}));
244
245 SimpleComponent testComponentNoTarget = (SimpleComponent) compositeComponent2.findComponent("testComponentNoTarget");
246 Assert.assertNotNull(testComponentNoTarget);
247 Assert.assertNotNull(testComponentNoTarget.getCustomMethod());
248 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
249 Assert.assertEquals("somethingFunny"+"x", testComponentNoTarget.getCustomMethod().invoke(facesContext.getELContext(), new Object[]{"x"}));
250 compositeComponent.popComponentFromEL(facesContext);
251
252 UINamingContainer compositeComponent3 = (UINamingContainer) compositeComponent.findComponent("simpleAttributeMethodExpressionNoTarget");
253 Assert.assertNotNull(compositeComponent3);
254 SimpleComponent testComponent3 = (SimpleComponent) compositeComponent3.findComponent("testComponent");
255 Assert.assertNotNull(testComponent3);
256 Assert.assertNotNull(testComponent3.getCustomMethod());
257 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
258 compositeComponent3.pushComponentToEL(facesContext, compositeComponent3);
259 Assert.assertEquals("somethingFunny"+"x", testComponent3.getCustomMethod().invoke(facesContext.getELContext(), new Object[]{"x"}));
260 compositeComponent3.popComponentFromEL(facesContext);
261 compositeComponent.popComponentFromEL(facesContext);
262
263 SimpleComponent testComponentNoTarget3 = (SimpleComponent) compositeComponent3.findComponent("testComponentNoTarget");
264 Assert.assertNotNull(testComponentNoTarget3);
265 Assert.assertNotNull(testComponentNoTarget3.getCustomMethod());
266 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
267 compositeComponent3.pushComponentToEL(facesContext, compositeComponent3);
268 Assert.assertEquals("somethingFunny"+"x", testComponentNoTarget3.getCustomMethod().invoke(facesContext.getELContext(), new Object[]{"x"}));
269 compositeComponent3.popComponentFromEL(facesContext);
270 compositeComponent.popComponentFromEL(facesContext);
271 }
272
273 @Test
274 public void testSimpleActionMethodExpressionTarget() throws Exception
275 {
276 MockAttributeBean bean = new MockAttributeBean();
277
278 facesContext.getExternalContext().getRequestMap().put("bean",
279 bean);
280
281 UIViewRoot root = facesContext.getViewRoot();
282 vdl.buildView(facesContext, root, "testSimpleAttributeActionMethodExpressionTarget.xhtml");
283
284
285 UIComponent panelGroup1 = root.findComponent("testGroup1");
286 Assert.assertNotNull(panelGroup1);
287 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
288 Assert.assertNotNull(compositeComponent);
289 UICommand testComponent = (UICommand) compositeComponent.findComponent("testComponent");
290 Assert.assertNotNull(testComponent);
291 Assert.assertNotNull(testComponent.getActionExpression());
292 Assert.assertEquals(bean.doSomeAction(), testComponent.getActionExpression().invoke(facesContext.getELContext(), null));
293 }
294
295 @Test
296 public void testCompositeActionMethodExpressionTarget() throws Exception
297 {
298 MockAttributeBean bean = new MockAttributeBean();
299
300 facesContext.getExternalContext().getRequestMap().put("bean",
301 bean);
302
303 UIViewRoot root = facesContext.getViewRoot();
304 vdl.buildView(facesContext, root, "testCompositeAttributeActionMethodExpressionTarget.xhtml");
305
306
307 UIComponent panelGroup1 = root.findComponent("testGroup1");
308 Assert.assertNotNull(panelGroup1);
309 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
310 Assert.assertNotNull(compositeComponent);
311
312 UINamingContainer compositeComponent2 = (UINamingContainer) compositeComponent.findComponent("simpleAttributeMethodExpressionTarget");
313 Assert.assertNotNull(compositeComponent2);
314 UICommand testComponent = (UICommand) compositeComponent2.findComponent("testComponent");
315 Assert.assertNotNull(testComponent);
316 Assert.assertNotNull(testComponent.getActionExpression());
317 Assert.assertEquals(bean.doSomeAction(), testComponent.getActionExpression().invoke(facesContext.getELContext(), null));
318 }
319
320 @Test
321 public void testSimpleActionMethodExpressionNoTarget() throws Exception
322 {
323 MockAttributeBean bean = new MockAttributeBean();
324
325 facesContext.getExternalContext().getRequestMap().put("bean",
326 bean);
327
328 UIViewRoot root = facesContext.getViewRoot();
329 vdl.buildView(facesContext, root, "testSimpleAttributeActionMethodExpressionNoTarget.xhtml");
330
331
332 UIComponent panelGroup1 = root.findComponent("testGroup1");
333 Assert.assertNotNull(panelGroup1);
334 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
335 Assert.assertNotNull(compositeComponent);
336 UICommand button = (UICommand) compositeComponent.findComponent("testComponentNoTarget");
337 Assert.assertNotNull(button);
338
339 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
340 button.pushComponentToEL(facesContext, button);
341 MethodExpression method = button.getActionExpression();
342 Assert.assertEquals(bean.doSomeAction(), method.invoke(facesContext.getELContext(), null));
343 button.popComponentFromEL(facesContext);
344 compositeComponent.popComponentFromEL(facesContext);
345
346 }
347
348 @Test
349 public void testCompositeActionMethodExpressionNoTarget() throws Exception
350 {
351 MockAttributeBean bean = new MockAttributeBean();
352
353 facesContext.getExternalContext().getRequestMap().put("bean",
354 bean);
355
356 UIViewRoot root = facesContext.getViewRoot();
357 vdl.buildView(facesContext, root, "testCompositeAttributeActionMethodExpressionNoTarget.xhtml");
358
359 UIComponent panelGroup1 = root.findComponent("testGroup1");
360 Assert.assertNotNull(panelGroup1);
361 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
362 Assert.assertNotNull(compositeComponent);
363
364 UINamingContainer compositeComponent3 = (UINamingContainer) compositeComponent.findComponent("simpleAttributeActionMethodExpressionNoTarget");
365 Assert.assertNotNull(compositeComponent3);
366 UICommand testComponentNoTarget3 = (UICommand) compositeComponent3.findComponent("testComponentNoTarget");
367 Assert.assertNotNull(testComponentNoTarget3);
368 Assert.assertNotNull(testComponentNoTarget3.getActionExpression());
369 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
370 compositeComponent.pushComponentToEL(facesContext, compositeComponent3);
371 Assert.assertEquals(bean.doSomeAction(), testComponentNoTarget3.getActionExpression().invoke(facesContext.getELContext(), null));
372 compositeComponent3.popComponentFromEL(facesContext);
373 compositeComponent.popComponentFromEL(facesContext);
374 }
375
376 @Test
377 public void testSimpleActionMethodExpressionTarget2() throws Exception
378 {
379 MockAttributeBean bean = new MockAttributeBean();
380
381 facesContext.getExternalContext().getRequestMap().put("bean",
382 bean);
383
384 UIViewRoot root = facesContext.getViewRoot();
385 vdl.buildView(facesContext, root, "testSimpleAttributeActionMethodExpressionTarget2.xhtml");
386
387
388 UIComponent panelGroup1 = root.findComponent("testGroup1");
389 Assert.assertNotNull(panelGroup1);
390 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
391 Assert.assertNotNull(compositeComponent);
392 UICommand testComponent = (UICommand) compositeComponent.findComponent("testComponent");
393 Assert.assertNotNull(testComponent);
394 Assert.assertNotNull(testComponent.getActionExpression());
395 Assert.assertEquals(bean.doSomeAction(), testComponent.getActionExpression().invoke(facesContext.getELContext(), null));
396
397 UICommand testComponentNoTarget = (UICommand) compositeComponent.findComponent("testComponentNoTarget");
398 Assert.assertNotNull(testComponentNoTarget);
399 Assert.assertNotNull(testComponentNoTarget.getActionExpression());
400 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
401 Assert.assertEquals(bean.doSomeAction(), testComponentNoTarget.getActionExpression().invoke(facesContext.getELContext(), null));
402 compositeComponent.popComponentFromEL(facesContext);
403 }
404
405 @Test
406 public void testSimpleActionMethodExpressionTarget3() throws Exception
407 {
408 MockAttributeBean bean = new MockAttributeBean();
409
410 facesContext.getExternalContext().getRequestMap().put("bean",
411 bean);
412
413 UIViewRoot root = facesContext.getViewRoot();
414 vdl.buildView(facesContext, root, "testSimpleAttributeActionMethodExpressionTarget3.xhtml");
415
416
417 UIComponent panelGroup1 = root.findComponent("testGroup1");
418 Assert.assertNotNull(panelGroup1);
419 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
420 Assert.assertNotNull(compositeComponent);
421 UICommand testComponent = (UICommand) compositeComponent.findComponent("testComponent");
422 Assert.assertNotNull(testComponent);
423 Assert.assertNotNull(testComponent.getActionExpression());
424 Assert.assertEquals(bean.doSomeAction(), testComponent.getActionExpression().invoke(facesContext.getELContext(), null));
425
426 UICommand testComponentNoTarget = (UICommand) compositeComponent.findComponent("testComponentNoTarget");
427 Assert.assertNotNull(testComponentNoTarget);
428 Assert.assertNotNull(testComponentNoTarget.getActionExpression());
429 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
430 Assert.assertEquals(bean.doSomeAction(), testComponentNoTarget.getActionExpression().invoke(facesContext.getELContext(), null));
431 compositeComponent.popComponentFromEL(facesContext);
432 }
433
434 @Test
435 public void testCompositeActionMethodExpressionTarget2() throws Exception
436 {
437 MockAttributeBean bean = new MockAttributeBean();
438
439 facesContext.getExternalContext().getRequestMap().put("bean",
440 bean);
441
442 UIViewRoot root = facesContext.getViewRoot();
443 vdl.buildView(facesContext, root, "testCompositeAttributeActionMethodExpressionTarget2.xhtml");
444
445
446 UIComponent panelGroup1 = root.findComponent("testGroup1");
447 Assert.assertNotNull(panelGroup1);
448 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
449 Assert.assertNotNull(compositeComponent);
450
451 UINamingContainer compositeComponent2 = (UINamingContainer) compositeComponent.findComponent("simpleAttributeMethodExpressionTarget");
452 Assert.assertNotNull(compositeComponent2);
453 UICommand testComponent = (UICommand) compositeComponent2.findComponent("testComponent");
454 Assert.assertNotNull(testComponent);
455 Assert.assertNotNull(testComponent.getActionExpression());
456 Assert.assertEquals(bean.doSomeAction(), testComponent.getActionExpression().invoke(facesContext.getELContext(), null));
457
458 UICommand testComponentNoTarget = (UICommand) compositeComponent2.findComponent("testComponentNoTarget");
459 Assert.assertNotNull(testComponentNoTarget);
460 Assert.assertNotNull(testComponentNoTarget.getActionExpression());
461 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
462 Assert.assertEquals(bean.doSomeAction(), testComponentNoTarget.getActionExpression().invoke(facesContext.getELContext(), null));
463 compositeComponent.popComponentFromEL(facesContext);
464
465 UINamingContainer compositeComponent3 = (UINamingContainer) compositeComponent.findComponent("simpleAttributeMethodExpressionNoTarget");
466 Assert.assertNotNull(compositeComponent3);
467 UICommand testComponent3 = (UICommand) compositeComponent3.findComponent("testComponent");
468 Assert.assertNotNull(testComponent3);
469 Assert.assertNotNull(testComponent3.getActionExpression());
470 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
471 compositeComponent3.pushComponentToEL(facesContext, compositeComponent3);
472 Assert.assertEquals(bean.doSomeAction(), testComponent3.getActionExpression().invoke(facesContext.getELContext(), null));
473 compositeComponent3.popComponentFromEL(facesContext);
474 compositeComponent.popComponentFromEL(facesContext);
475
476 UICommand testComponentNoTarget3 = (UICommand) compositeComponent3.findComponent("testComponentNoTarget");
477 Assert.assertNotNull(testComponentNoTarget3);
478 Assert.assertNotNull(testComponentNoTarget3.getActionExpression());
479 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
480 compositeComponent3.pushComponentToEL(facesContext, compositeComponent3);
481 Assert.assertEquals(bean.doSomeAction(), testComponentNoTarget3.getActionExpression().invoke(facesContext.getELContext(), null));
482 compositeComponent3.popComponentFromEL(facesContext);
483 compositeComponent.popComponentFromEL(facesContext);
484 }
485
486 @Test
487 public void testCompositeActionMethodExpressionNoTarget2() throws Exception
488 {
489 MockAttributeBean bean = new MockAttributeBean();
490
491 facesContext.getExternalContext().getRequestMap().put("bean",
492 bean);
493
494 UIViewRoot root = facesContext.getViewRoot();
495 vdl.buildView(facesContext, root, "testCompositeAttributeActionMethodExpressionNoTarget2.xhtml");
496
497 UIComponent panelGroup1 = root.findComponent("testGroup1");
498 Assert.assertNotNull(panelGroup1);
499 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
500 Assert.assertNotNull(compositeComponent);
501
502 UINamingContainer compositeComponent2 = (UINamingContainer) compositeComponent.findComponent("compositeAttributeMethodExpressionNoTarget");
503 Assert.assertNotNull(compositeComponent2);
504 UINamingContainer compositeComponent3 = (UINamingContainer) compositeComponent2.findComponent("simpleAttributeMethodExpressionNoTarget");
505 Assert.assertNotNull(compositeComponent3);
506 UICommand testComponentNoTarget3 = (UICommand) compositeComponent3.findComponent("testComponentNoTarget");
507 Assert.assertNotNull(testComponentNoTarget3);
508 Assert.assertNotNull(testComponentNoTarget3.getActionExpression());
509 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
510 compositeComponent.pushComponentToEL(facesContext, compositeComponent3);
511 Assert.assertEquals(bean.doSomeAction(), testComponentNoTarget3.getActionExpression().invoke(facesContext.getELContext(), null));
512 compositeComponent3.popComponentFromEL(facesContext);
513 compositeComponent.popComponentFromEL(facesContext);
514 }
515
516 @Test
517 public void testCompositeActionMethodExpressionTarget3() throws Exception
518 {
519 MockAttributeBean bean = new MockAttributeBean();
520
521 facesContext.getExternalContext().getRequestMap().put("bean",
522 bean);
523
524 UIViewRoot root = facesContext.getViewRoot();
525 vdl.buildView(facesContext, root, "testCompositeAttributeActionMethodExpressionTarget3.xhtml");
526
527
528 UIComponent panelGroup1 = root.findComponent("testGroup1");
529 Assert.assertNotNull(panelGroup1);
530 UINamingContainer compositeComponent = (UINamingContainer) panelGroup1.getChildren().get(0);
531 Assert.assertNotNull(compositeComponent);
532
533 UINamingContainer compositeComponent2 = (UINamingContainer) compositeComponent.findComponent("simpleAttributeMethodExpressionTarget");
534 Assert.assertNotNull(compositeComponent2);
535 UICommand testComponent = (UICommand) compositeComponent2.findComponent("testComponent");
536 Assert.assertNotNull(testComponent);
537 Assert.assertNotNull(testComponent.getActionExpression());
538 Assert.assertEquals(bean.doSomeAction(), testComponent.getActionExpression().invoke(facesContext.getELContext(), null));
539
540 UICommand testComponentNoTarget = (UICommand) compositeComponent2.findComponent("testComponentNoTarget");
541 Assert.assertNotNull(testComponentNoTarget);
542 Assert.assertNotNull(testComponentNoTarget.getActionExpression());
543 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
544 compositeComponent2.pushComponentToEL(facesContext, compositeComponent2);
545 Assert.assertEquals(bean.doSomeAction(), testComponentNoTarget.getActionExpression().invoke(facesContext.getELContext(), null));
546 compositeComponent2.popComponentFromEL(facesContext);
547 compositeComponent.popComponentFromEL(facesContext);
548
549 UINamingContainer compositeComponent3 = (UINamingContainer) compositeComponent.findComponent("simpleAttributeMethodExpressionNoTarget");
550 Assert.assertNotNull(compositeComponent3);
551 UICommand testComponent3 = (UICommand) compositeComponent3.findComponent("testComponent");
552 Assert.assertNotNull(testComponent3);
553 Assert.assertNotNull(testComponent3.getActionExpression());
554 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
555 compositeComponent3.pushComponentToEL(facesContext, compositeComponent3);
556 Assert.assertEquals(bean.doSomeAction(), testComponent3.getActionExpression().invoke(facesContext.getELContext(), null));
557 compositeComponent3.popComponentFromEL(facesContext);
558 compositeComponent.popComponentFromEL(facesContext);
559
560 UICommand testComponentNoTarget3 = (UICommand) compositeComponent3.findComponent("testComponentNoTarget");
561 Assert.assertNotNull(testComponentNoTarget3);
562 Assert.assertNotNull(testComponentNoTarget3.getActionExpression());
563 compositeComponent.pushComponentToEL(facesContext, compositeComponent);
564 compositeComponent3.pushComponentToEL(facesContext, compositeComponent3);
565 Assert.assertEquals(bean.doSomeAction(), testComponentNoTarget3.getActionExpression().invoke(facesContext.getELContext(), null));
566 compositeComponent3.popComponentFromEL(facesContext);
567 compositeComponent.popComponentFromEL(facesContext);
568 }
569
570
571 }