View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.view.facelets.compiler;
20  
21  import java.util.HashSet;
22  import java.util.Set;
23  
24  import javax.faces.application.StateManager;
25  import javax.faces.component.UIComponent;
26  import javax.faces.component.UIOutput;
27  import javax.faces.component.UIViewRoot;
28  import javax.faces.event.PhaseId;
29  import javax.faces.render.RenderKitFactory;
30  import javax.faces.render.ResponseStateManager;
31  
32  import org.apache.myfaces.application.StateManagerImpl;
33  import org.apache.myfaces.renderkit.html.HtmlResponseStateManager;
34  import org.apache.myfaces.shared.config.MyfacesConfig;
35  import org.apache.myfaces.shared.util.StateUtils;
36  import org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory;
37  import org.apache.myfaces.test.mock.MockRenderKit;
38  import org.apache.myfaces.view.facelets.FaceletMultipleRequestsTestCase;
39  import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
40  import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
41  import org.junit.Test;
42  import org.testng.Assert;
43  
44  public class UniqueComponentIdTestCase extends FaceletMultipleRequestsTestCase
45  {
46  
47      @Override
48      protected void setUpApplication() throws Exception
49      {
50          super.setUpApplication();
51          
52          application.setStateManager(new StateManagerImpl());
53      }
54      
55      @Override
56      protected void setUpServletContextAndSession() throws Exception
57      {
58          super.setUpServletContextAndSession();
59          
60          servletContext.addInitParameter(StateManager.PARTIAL_STATE_SAVING_PARAM_NAME, "true");
61          servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_SERVER);
62          servletContext.addInitParameter(FaceletViewDeclarationLanguage.PARAM_REFRESH_PERIOD, "-1");
63          servletContext.setAttribute(MyfacesConfig.class.getName(), new MyfacesConfig());
64      }
65      
66      /**
67       * @throws Exception
68       */
69      @Test
70      public void testUniqueComponentIdCif() throws Exception
71      {
72          /* For this example:
73           * 
74           *   <h:outputText value="-A-"/>
75           *   <c:if test="#{condition}">
76           *   <h:outputText value="-B-"/>
77           *   </c:if>
78           *   <h:outputText value="-C-"/>
79           *
80           * the same tag-component unique id and component id should be generated
81           * without taking into account the value on the condition.
82           */
83          String viewStateParam = null;
84          String componentBid = null;
85          String tagBId = null;
86          Set<String> tagUniqueIdSet = new HashSet<String>();
87          Set<String> componentIdSet = new HashSet<String>();
88          try
89          {
90              setupRequest();
91              facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
92              request.setAttribute("condition", true);
93              UIViewRoot root = facesContext.getViewRoot();
94              root.setViewId("/testUniqueComponentIdCif.xhtml");
95              vdl.buildView(facesContext, root, "/testUniqueComponentIdCif.xhtml");
96  
97              
98              //1. test unique MARK_CREATED id
99              for (UIComponent child : root.getChildren())
100             {
101                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
102                 if (tagUniqueIdSet.contains(id))
103                 {
104                     Assert.fail();
105                 }
106                 tagUniqueIdSet.add(id);
107                 String componentId = child.getId();
108                 if (componentIdSet.contains(componentId))
109                 {
110                     Assert.fail();
111                 }
112                 componentIdSet.add(componentId);
113                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
114                 {
115                     if ("-B-".equals(((UIOutput)child).getValue()))
116                     {
117                         componentBid = componentId;
118                         tagBId = id;
119                     }
120                 }
121             }
122             
123             Assert.assertNotNull(componentBid);
124             Assert.assertNotNull(tagBId);
125             
126             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
127             
128             viewStateParam = application.getStateManager().getViewState(facesContext);
129         }
130         finally
131         {
132             tearDownRequest();
133         }
134 
135         tagUniqueIdSet.remove(tagBId);
136         componentIdSet.remove(componentBid);
137 
138         try
139         {
140             setupRequest();
141             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
142             request.setAttribute("condition", false);
143             UIViewRoot root = facesContext.getViewRoot();
144             root.setViewId("/testUniqueComponentIdCif.xhtml");
145             vdl.buildView(facesContext, root, "/testUniqueComponentIdCif.xhtml");
146 
147             
148             //1. test unique MARK_CREATED id
149             for (UIComponent child : root.getChildren())
150             {
151                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
152                 if (!tagUniqueIdSet.contains(id))
153                 {
154                     Assert.fail();
155                 }
156                 String componentId = child.getId();
157                 if (!componentIdSet.contains(componentId))
158                 {
159                     Assert.fail();
160                 }
161             }
162             
163             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
164             
165             viewStateParam = application.getStateManager().getViewState(facesContext);
166         }
167         finally
168         {
169             tearDownRequest();
170         }
171 
172     }
173     
174     /**
175      * @throws Exception
176      */
177     @Test
178     public void testUniqueComponentIdCifSaveCondition() throws Exception
179     {
180         /* For this example:
181          * 
182          *   <h:outputText value="-A-"/>
183          *   <c:if test="#{condition}">
184          *   <h:outputText value="-B-"/>
185          *   </c:if>
186          *   <h:outputText value="-C-"/>
187          *
188          * When the view is restored, the condition should not be evaluated. Instead,
189          * the value should be retrieved from the state, to ensure PSS initial conditions.
190          * 
191          * Then, try to refresh the view and check if the condition is evaluated.
192          * Again the ids should be the same, but -B- component is removed from view
193          */
194         String viewStateParam = null;
195         String componentBid = null;
196         String tagBId = null;
197         Set<String> tagUniqueIdSet = new HashSet<String>();
198         Set<String> componentIdSet = new HashSet<String>();
199         
200         ((MockRenderKit)renderKit).setResponseStateManager(new HtmlResponseStateManager());
201         StateUtils.initSecret(servletContext);
202         servletContext.setAttribute(StateUtils.SERIAL_FACTORY, new DefaultSerialFactory());
203         try
204         {
205             setupRequest();
206             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
207             request.setAttribute("condition", true);
208             UIViewRoot root = facesContext.getViewRoot();
209             root.setViewId("/testUniqueComponentIdCif.xhtml");
210             vdl.buildView(facesContext, root, "/testUniqueComponentIdCif.xhtml");
211 
212             
213             //1. test unique MARK_CREATED id
214             for (UIComponent child : root.getChildren())
215             {
216                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
217                 if (tagUniqueIdSet.contains(id))
218                 {
219                     Assert.fail();
220                 }
221                 tagUniqueIdSet.add(id);
222                 String componentId = child.getId();
223                 if (componentIdSet.contains(componentId))
224                 {
225                     Assert.fail();
226                 }
227                 componentIdSet.add(componentId);
228                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
229                 {
230                     if ("-B-".equals(((UIOutput)child).getValue()))
231                     {
232                         componentBid = componentId;
233                         tagBId = id;
234                     }
235                 }
236             }
237             
238             Assert.assertNotNull(componentBid);
239             Assert.assertNotNull(tagBId);
240             
241             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
242             
243             viewStateParam = application.getStateManager().getViewState(facesContext);
244         }
245         finally
246         {
247             tearDownRequest();
248         }
249 
250         try
251         {
252             setupRequest();
253             facesContext.setCurrentPhaseId(PhaseId.RESTORE_VIEW);
254             request.setAttribute("condition", false);
255             request.addParameter(ResponseStateManager.VIEW_STATE_PARAM, viewStateParam);
256     
257             UIViewRoot root = application.getStateManager().restoreView(facesContext, "/testUniqueComponentIdCif.xhtml", RenderKitFactory.HTML_BASIC_RENDER_KIT);
258 
259             Assert.assertNotNull(root);
260             
261             boolean restoredB = false;
262             //1. test unique MARK_CREATED id
263             for (UIComponent child : root.getChildren())
264             {
265                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
266                 if (!tagUniqueIdSet.contains(id))
267                 {
268                     Assert.fail();
269                 }
270                 String componentId = child.getId();
271                 if (!componentIdSet.contains(componentId))
272                 {
273                     Assert.fail();
274                 }
275                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
276                 {
277                     if ("-B-".equals(((UIOutput)child).getValue()))
278                     {
279                         restoredB = true;
280                     }
281                 }
282             }
283             
284             Assert.assertTrue(restoredB);
285             
286             //Now let's refresh the view on render response, to reflect the value on the condition
287             tagUniqueIdSet.remove(tagBId);
288             componentIdSet.remove(componentBid);
289             
290             //Refresh!
291             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
292             vdl.buildView(facesContext, root, "/testUniqueComponentIdCif.xhtml");
293             
294             //1. test unique MARK_CREATED id
295             for (UIComponent child : root.getChildren())
296             {
297                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
298                 if (!tagUniqueIdSet.contains(id))
299                 {
300                     Assert.fail();
301                 }
302                 String componentId = child.getId();
303                 if (!componentIdSet.contains(componentId))
304                 {
305                     Assert.fail();
306                 }
307             }
308         }
309         finally
310         {
311             tearDownRequest();
312         }
313     }
314     
315     /**
316      * @throws Exception
317      */
318     @Test
319     public void testUniqueComponentIdInclude1_1() throws Exception
320     {
321         /* For this example:
322          * 
323          * <h:outputText value="-A-"/>
324          * <ui:include src="#{pageSelected}"/>
325          * <h:outputText value="-C-"/>
326          * 
327          * included page
328          * 
329          * <h:outputText value="-B-"/
330          *
331          * the same tag-component unique id and component id should be generated
332          * without taking into account the components on the included page.
333          */
334         String viewStateParam = null;
335         String componentBid = null;
336         String tagBId = null;
337         Set<String> tagUniqueIdSet = new HashSet<String>();
338         Set<String> componentIdSet = new HashSet<String>();
339         try
340         {
341             setupRequest();
342             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
343             request.setAttribute("pageSelected", "testUniqueComponentIdInclude1_1.xhtml");
344             UIViewRoot root = facesContext.getViewRoot();
345             root.setViewId("/testUniqueComponentIdInclude1.xhtml");
346             vdl.buildView(facesContext, root, "/testUniqueComponentIdInclude1.xhtml");
347 
348             
349             //1. test unique MARK_CREATED id
350             for (UIComponent child : root.getChildren())
351             {
352                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
353                 if (tagUniqueIdSet.contains(id))
354                 {
355                     Assert.fail();
356                 }
357                 tagUniqueIdSet.add(id);
358                 String componentId = child.getId();
359                 if (componentIdSet.contains(componentId))
360                 {
361                     Assert.fail();
362                 }
363                 componentIdSet.add(componentId);
364                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
365                 {
366                     if ("-B-".equals(((UIOutput)child).getValue()))
367                     {
368                         componentBid = componentId;
369                         tagBId = id;
370                     }
371                 }
372             }
373             
374             Assert.assertNotNull(componentBid);
375             Assert.assertNotNull(tagBId);
376             
377             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
378             
379             viewStateParam = application.getStateManager().getViewState(facesContext);
380         }
381         finally
382         {
383             tearDownRequest();
384         }
385 
386         tagUniqueIdSet.remove(tagBId);
387         componentIdSet.remove(componentBid);
388 
389         try
390         {
391             setupRequest();
392             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
393             request.setAttribute("pageSelected", "testUniqueComponentIdInclude1_0.xhtml");
394             UIViewRoot root = facesContext.getViewRoot();
395             root.setViewId("/testUniqueComponentIdInclude1.xhtml");
396             vdl.buildView(facesContext, root, "/testUniqueComponentIdInclude1.xhtml");
397 
398             
399             //1. test unique MARK_CREATED id
400             for (UIComponent child : root.getChildren())
401             {
402                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
403                 if (!tagUniqueIdSet.contains(id))
404                 {
405                     Assert.fail();
406                 }
407                 String componentId = child.getId();
408                 if (!componentIdSet.contains(componentId))
409                 {
410                     Assert.fail();
411                 }
412             }
413             
414             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
415             
416             viewStateParam = application.getStateManager().getViewState(facesContext);
417         }
418         finally
419         {
420             tearDownRequest();
421         }
422 
423     }
424 
425     @Test
426     public void testUniqueComponentIdInclude1_2() throws Exception
427     {
428         /* For this example:
429          * 
430          * <h:outputText value="-A-"/>
431          * <ui:include src="#{pageSelected}"/>
432          * <h:outputText value="-C-"/>
433          * 
434          * included page 1
435          * 
436          * <h:outputText value="-B-"/>
437          * 
438          * included page 2
439          * 
440          * <h:outputText value="-B-"/>
441          *
442          * the same tag-component unique id and component id should be generated
443          * without taking into account the components on the included page.
444          * 
445          * Since the component -B- was defined on a different page, is a different
446          * component and its values should not be related (but its component ids
447          * could be the same). This condition ensure refreshing algorithm will
448          * not mix components between two views.
449          */
450         String viewStateParam = null;
451         String componentBid = null;
452         String tagBId = null;
453         Set<String> tagUniqueIdSet = new HashSet<String>();
454         Set<String> componentIdSet = new HashSet<String>();
455         try
456         {
457             setupRequest();
458             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
459             request.setAttribute("pageSelected", "testUniqueComponentIdInclude1_1.xhtml");
460             UIViewRoot root = facesContext.getViewRoot();
461             root.setViewId("/testUniqueComponentIdInclude1.xhtml");
462             vdl.buildView(facesContext, root, "/testUniqueComponentIdInclude1.xhtml");
463 
464             
465             //1. test unique MARK_CREATED id
466             for (UIComponent child : root.getChildren())
467             {
468                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
469                 if (tagUniqueIdSet.contains(id))
470                 {
471                     Assert.fail();
472                 }
473                 tagUniqueIdSet.add(id);
474                 String componentId = child.getId();
475                 if (componentIdSet.contains(componentId))
476                 {
477                     Assert.fail();
478                 }
479                 componentIdSet.add(componentId);
480                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
481                 {
482                     if ("-B-".equals(((UIOutput)child).getValue()))
483                     {
484                         componentBid = componentId;
485                         tagBId = id;
486                     }
487                 }
488             }
489             
490             Assert.assertNotNull(componentBid);
491             Assert.assertNotNull(tagBId);
492             
493             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
494             
495             viewStateParam = application.getStateManager().getViewState(facesContext);
496         }
497         finally
498         {
499             tearDownRequest();
500         }
501 
502         tagUniqueIdSet.remove(tagBId);
503         componentIdSet.remove(componentBid);
504 
505         try
506         {
507             setupRequest();
508             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
509             request.setAttribute("pageSelected", "testUniqueComponentIdInclude1_2.xhtml");
510             UIViewRoot root = facesContext.getViewRoot();
511             root.setViewId("/testUniqueComponentIdInclude1.xhtml");
512             vdl.buildView(facesContext, root, "/testUniqueComponentIdInclude1.xhtml");
513 
514             
515             //1. test unique MARK_CREATED id
516             for (UIComponent child : root.getChildren())
517             {
518                 String componentId = child.getId();
519                 
520                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
521                 if (componentBid.equals(componentId))
522                 {
523                     Assert.assertFalse(tagBId.equals(id));
524                 }
525                 else
526                 {
527                     if (!tagUniqueIdSet.contains(id))
528                     {
529                         Assert.fail();
530                     }
531                     if (!componentIdSet.contains(componentId))
532                     {
533                         Assert.fail();
534                     }
535                 }
536             }
537             
538             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
539             
540             viewStateParam = application.getStateManager().getViewState(facesContext);
541         }
542         finally
543         {
544             tearDownRequest();
545         }
546 
547     }
548 
549     /**
550      * @throws Exception
551      */
552     @Test
553     public void testUniqueComponentIdIncludeSaveCondition() throws Exception
554     {
555         /* For this example:
556          * 
557          * <h:outputText value="-A-"/>
558          * <ui:include src="#{pageSelected}"/>
559          * <h:outputText value="-C-"/>
560          * 
561          * included page
562          * 
563          * <h:outputText value="-B-"/
564          *
565          * the same tag-component unique id and component id should be generated
566          * without taking into account the components on the included page.
567          *
568          * When the view is restored, the pageSelected EL should not be evaluated. Instead,
569          * the value should be retrieved from the state, to ensure PSS initial conditions.
570          * 
571          * Then, try to refresh the view and check if the pageSelected EL is evaluated.
572          * Again the ids should be the same, but -B- component is removed from view
573          */
574         String viewStateParam = null;
575         String componentBid = null;
576         String tagBId = null;
577         Set<String> tagUniqueIdSet = new HashSet<String>();
578         Set<String> componentIdSet = new HashSet<String>();
579         
580         ((MockRenderKit)renderKit).setResponseStateManager(new HtmlResponseStateManager());
581         StateUtils.initSecret(servletContext);
582         servletContext.setAttribute(StateUtils.SERIAL_FACTORY, new DefaultSerialFactory());
583         try
584         {
585             setupRequest();
586             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
587             request.setAttribute("pageSelected", "testUniqueComponentIdInclude1_1.xhtml");
588             UIViewRoot root = facesContext.getViewRoot();
589             root.setViewId("/testUniqueComponentIdInclude1.xhtml");
590             vdl.buildView(facesContext, root, "/testUniqueComponentIdInclude1.xhtml");
591 
592             
593             //1. test unique MARK_CREATED id
594             for (UIComponent child : root.getChildren())
595             {
596                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
597                 if (tagUniqueIdSet.contains(id))
598                 {
599                     Assert.fail();
600                 }
601                 tagUniqueIdSet.add(id);
602                 String componentId = child.getId();
603                 if (componentIdSet.contains(componentId))
604                 {
605                     Assert.fail();
606                 }
607                 componentIdSet.add(componentId);
608                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
609                 {
610                     if ("-B-".equals(((UIOutput)child).getValue()))
611                     {
612                         componentBid = componentId;
613                         tagBId = id;
614                         child.getAttributes().put("test", "test");
615                     }
616                 }
617             }
618             
619             Assert.assertNotNull(componentBid);
620             Assert.assertNotNull(tagBId);
621             
622             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
623             
624             viewStateParam = application.getStateManager().getViewState(facesContext);
625         }
626         finally
627         {
628             tearDownRequest();
629         }
630 
631         try
632         {
633             setupRequest();
634             facesContext.setCurrentPhaseId(PhaseId.RESTORE_VIEW);
635             request.setAttribute("pageSelected", "testUniqueComponentIdInclude1_0.xhtml");
636             request.addParameter(ResponseStateManager.VIEW_STATE_PARAM, viewStateParam);
637     
638             UIViewRoot root = application.getStateManager().restoreView(facesContext, "/testUniqueComponentIdInclude1.xhtml", RenderKitFactory.HTML_BASIC_RENDER_KIT);
639 
640             Assert.assertNotNull(root);
641             
642             boolean restoredB = false;
643             //1. test unique MARK_CREATED id
644             for (UIComponent child : root.getChildren())
645             {
646                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
647                 if (!tagUniqueIdSet.contains(id))
648                 {
649                     Assert.fail();
650                 }
651                 String componentId = child.getId();
652                 if (!componentIdSet.contains(componentId))
653                 {
654                     Assert.fail();
655                 }
656                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
657                 {
658                     if ("-B-".equals(((UIOutput)child).getValue()))
659                     {
660                         restoredB = true;
661                         Assert.assertNotNull(child.getAttributes().get("test"));
662                     }
663                 }
664             }
665             
666             Assert.assertTrue(restoredB);
667             
668             //Now let's refresh the view on render response, to reflect the value on the condition
669             tagUniqueIdSet.remove(tagBId);
670             componentIdSet.remove(componentBid);
671             
672             //Refresh!
673             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
674             vdl.buildView(facesContext, root, "/testUniqueComponentIdInclude1.xhtml");
675             
676             //1. test unique MARK_CREATED id
677             for (UIComponent child : root.getChildren())
678             {
679                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
680                 if (!tagUniqueIdSet.contains(id))
681                 {
682                     Assert.fail();
683                 }
684                 String componentId = child.getId();
685                 if (!componentIdSet.contains(componentId))
686                 {
687                     Assert.fail();
688                 }
689             }
690         }
691         finally
692         {
693             tearDownRequest();
694         }
695     }
696     
697     @Test
698     public void testUniqueComponentIdIncludeSaveCondition2() throws Exception
699     {
700         /* For this example:
701          * 
702          * <h:outputText value="-A-"/>
703          * <ui:include src="#{pageSelected}"/>
704          * <h:outputText value="-C-"/>
705          * 
706          * included page
707          * 
708          * <h:outputText value="-B-"/
709          *
710          * the same tag-component unique id and component id should be generated
711          * without taking into account the components on the included page.
712          *
713          * When the view is restored, the pageSelected EL should not be evaluated. Instead,
714          * the value should be retrieved from the state, to ensure PSS initial conditions.
715          * 
716          * Then, try to refresh the view and check if the pageSelected EL is evaluated.
717          * Again the ids should be the same, but -B- component is removed from view
718          * Since testUniqueComponentIdInclude1_1 and testUniqueComponentIdInclude1_2 are
719          * identical copies of the same file, we should check if c:if add/remove algorithm
720          * can detect the difference.
721          */
722         String viewStateParam = null;
723         String componentBid = null;
724         String tagBId = null;
725         Set<String> tagUniqueIdSet = new HashSet<String>();
726         Set<String> componentIdSet = new HashSet<String>();
727         
728         ((MockRenderKit)renderKit).setResponseStateManager(new HtmlResponseStateManager());
729         StateUtils.initSecret(servletContext);
730         servletContext.setAttribute(StateUtils.SERIAL_FACTORY, new DefaultSerialFactory());
731         try
732         {
733             setupRequest();
734             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
735             request.setAttribute("pageSelected", "testUniqueComponentIdInclude1_1.xhtml");
736             UIViewRoot root = facesContext.getViewRoot();
737             root.setViewId("/testUniqueComponentIdInclude1.xhtml");
738             vdl.buildView(facesContext, root, "/testUniqueComponentIdInclude1.xhtml");
739 
740             
741             //1. test unique MARK_CREATED id
742             for (UIComponent child : root.getChildren())
743             {
744                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
745                 if (tagUniqueIdSet.contains(id))
746                 {
747                     Assert.fail();
748                 }
749                 tagUniqueIdSet.add(id);
750                 String componentId = child.getId();
751                 if (componentIdSet.contains(componentId))
752                 {
753                     Assert.fail();
754                 }
755                 componentIdSet.add(componentId);
756                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
757                 {
758                     if ("-B-".equals(((UIOutput)child).getValue()))
759                     {
760                         componentBid = componentId;
761                         tagBId = id;
762                         child.getAttributes().put("test", "test");
763                     }
764                 }
765             }
766             
767             Assert.assertNotNull(componentBid);
768             Assert.assertNotNull(tagBId);
769             
770             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
771             
772             viewStateParam = application.getStateManager().getViewState(facesContext);
773         }
774         finally
775         {
776             tearDownRequest();
777         }
778 
779         try
780         {
781             setupRequest();
782             facesContext.setCurrentPhaseId(PhaseId.RESTORE_VIEW);
783             request.setAttribute("pageSelected", "testUniqueComponentIdInclude1_2.xhtml");
784             request.addParameter(ResponseStateManager.VIEW_STATE_PARAM, viewStateParam);
785     
786             UIViewRoot root = application.getStateManager().restoreView(facesContext, "/testUniqueComponentIdInclude1.xhtml", RenderKitFactory.HTML_BASIC_RENDER_KIT);
787 
788             Assert.assertNotNull(root);
789             
790             boolean restoredB = false;
791             //1. test unique MARK_CREATED id
792             for (UIComponent child : root.getChildren())
793             {
794                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
795                 if (!tagUniqueIdSet.contains(id))
796                 {
797                     Assert.fail();
798                 }
799                 String componentId = child.getId();
800                 if (!componentIdSet.contains(componentId))
801                 {
802                     Assert.fail();
803                 }
804                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
805                 {
806                     if ("-B-".equals(((UIOutput)child).getValue()))
807                     {
808                         restoredB = true;
809                         Assert.assertNotNull(child.getAttributes().get("test"));
810                     }
811                 }
812             }
813             
814             Assert.assertTrue(restoredB);
815             
816             //Now let's refresh the view on render response, to reflect the value on the condition
817             tagUniqueIdSet.remove(tagBId);
818             componentIdSet.remove(componentBid);
819             
820             //Refresh!
821             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
822             vdl.buildView(facesContext, root, "/testUniqueComponentIdInclude1.xhtml");
823             
824             restoredB = false;
825             
826             //1. test unique MARK_CREATED id
827             for (UIComponent child : root.getChildren())
828             {
829                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
830                 String componentId = child.getId();
831                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
832                 {
833                     if ("-B-".equals(((UIOutput)child).getValue()))
834                     {
835                         restoredB = true;
836                         //Check if the B component is not the same as before. 
837                         //It should have different tag-component id and its state is different.
838                         Assert.assertFalse(tagBId.equals(id));
839                         Assert.assertNull(child.getAttributes().get("test"));
840                     }
841                 }
842                 else
843                 {
844                     if (!tagUniqueIdSet.contains(id))
845                     {
846                         Assert.fail();
847                     }
848                     if (!componentIdSet.contains(componentId))
849                     {
850                         Assert.fail();
851                     }
852                 }
853             }
854             
855             Assert.assertTrue(restoredB);
856         }
857         finally
858         {
859             tearDownRequest();
860         }
861     }
862 
863     /**
864      * @throws Exception
865      */
866     @Test
867     public void testUniqueComponentIdDecorate1_1() throws Exception
868     {
869         String viewStateParam = null;
870         String componentBid = null;
871         String tagBId = null;
872         String componentDid = null;
873         String tagDId = null;
874         Set<String> tagUniqueIdSet = new HashSet<String>();
875         Set<String> componentIdSet = new HashSet<String>();
876         try
877         {
878             setupRequest();
879             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
880             request.setAttribute("pageSelected", "testUniqueComponentIdDecorate1_1.xhtml");
881             UIViewRoot root = facesContext.getViewRoot();
882             root.setViewId("/testUniqueComponentIdDecorate1.xhtml");
883             vdl.buildView(facesContext, root, "/testUniqueComponentIdDecorate1.xhtml");
884 
885             
886             //1. test unique MARK_CREATED id
887             for (UIComponent child : root.getChildren())
888             {
889                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
890                 if (tagUniqueIdSet.contains(id))
891                 {
892                     Assert.fail();
893                 }
894                 tagUniqueIdSet.add(id);
895                 String componentId = child.getId();
896                 if (componentIdSet.contains(componentId))
897                 {
898                     Assert.fail();
899                 }
900                 componentIdSet.add(componentId);
901                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
902                 {
903                     if ("-B-".equals(((UIOutput)child).getValue()))
904                     {
905                         componentBid = componentId;
906                         tagBId = id;
907                     }
908                     if ("-D-".equals(((UIOutput)child).getValue()))
909                     {
910                         componentDid = componentId;
911                         tagDId = id;
912                     }
913                 }
914             }
915             
916             Assert.assertNotNull(componentBid);
917             Assert.assertNotNull(tagBId);
918             Assert.assertNotNull(componentDid);
919             Assert.assertNotNull(tagDId);
920             
921             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
922             
923             viewStateParam = application.getStateManager().getViewState(facesContext);
924         }
925         finally
926         {
927             tearDownRequest();
928         }
929 
930         tagUniqueIdSet.remove(tagBId);
931         componentIdSet.remove(componentBid);
932         tagUniqueIdSet.remove(tagDId);
933         componentIdSet.remove(componentDid);
934 
935         try
936         {
937             setupRequest();
938             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
939             request.setAttribute("pageSelected", "testUniqueComponentIdDecorate1_0.xhtml");
940             UIViewRoot root = facesContext.getViewRoot();
941             root.setViewId("/testUniqueComponentIdDecorate1.xhtml");
942             vdl.buildView(facesContext, root, "/testUniqueComponentIdDecorate1.xhtml");
943 
944             
945             //1. test unique MARK_CREATED id
946             for (UIComponent child : root.getChildren())
947             {
948                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
949                 String componentId = child.getId();
950                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
951                 {
952                     if ("-C-".equals(((UIOutput)child).getValue()))
953                     {
954                         //This is a different C, because it the template is different
955                         //the final component id could be the same or different, but the
956                         //important here is refreshing algorithm should not mix both 
957                         Assert.assertTrue(!tagUniqueIdSet.contains(id));
958                     }
959                     else
960                     {
961                         if (!tagUniqueIdSet.contains(id))
962                         {
963                             Assert.fail();
964                         }
965                         if (!componentIdSet.contains(componentId))
966                         {
967                             Assert.fail();
968                         }
969                     }
970                 }
971                 else
972                 {
973                     if (!tagUniqueIdSet.contains(id))
974                     {
975                         Assert.fail();
976                     }
977                     if (!componentIdSet.contains(componentId))
978                     {
979                         Assert.fail();
980                     }
981                 }
982             }
983             
984             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
985             
986             viewStateParam = application.getStateManager().getViewState(facesContext);
987         }
988         finally
989         {
990             tearDownRequest();
991         }
992 
993     }
994 
995     /**
996      * @throws Exception
997      */
998     @Test
999     public void testUniqueComponentIdDecorate1_2() throws Exception
1000     {
1001         String viewStateParam = null;
1002         String componentBid = null;
1003         String tagBId = null;
1004         String componentDid = null;
1005         String tagDId = null;
1006         Set<String> tagUniqueIdSet = new HashSet<String>();
1007         Set<String> componentIdSet = new HashSet<String>();
1008         try
1009         {
1010             setupRequest();
1011             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
1012             request.setAttribute("pageSelected", "testUniqueComponentIdDecorate1_1.xhtml");
1013             UIViewRoot root = facesContext.getViewRoot();
1014             root.setViewId("/testUniqueComponentIdDecorate1.xhtml");
1015             vdl.buildView(facesContext, root, "/testUniqueComponentIdDecorate1.xhtml");
1016 
1017             
1018             //1. test unique MARK_CREATED id
1019             for (UIComponent child : root.getChildren())
1020             {
1021                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
1022                 if (tagUniqueIdSet.contains(id))
1023                 {
1024                     Assert.fail();
1025                 }
1026                 tagUniqueIdSet.add(id);
1027                 String componentId = child.getId();
1028                 if (componentIdSet.contains(componentId))
1029                 {
1030                     Assert.fail();
1031                 }
1032                 componentIdSet.add(componentId);
1033                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
1034                 {
1035                     if ("-B-".equals(((UIOutput)child).getValue()))
1036                     {
1037                         componentBid = componentId;
1038                         tagBId = id;
1039                     }
1040                     if ("-D-".equals(((UIOutput)child).getValue()))
1041                     {
1042                         componentDid = componentId;
1043                         tagDId = id;
1044                     }
1045                 }
1046             }
1047             
1048             Assert.assertNotNull(componentBid);
1049             Assert.assertNotNull(tagBId);
1050             Assert.assertNotNull(componentDid);
1051             Assert.assertNotNull(tagDId);
1052             
1053             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
1054             
1055             viewStateParam = application.getStateManager().getViewState(facesContext);
1056         }
1057         finally
1058         {
1059             tearDownRequest();
1060         }
1061 
1062         tagUniqueIdSet.remove(tagBId);
1063         componentIdSet.remove(componentBid);
1064         tagUniqueIdSet.remove(tagDId);
1065         componentIdSet.remove(componentDid);
1066 
1067         try
1068         {
1069             setupRequest();
1070             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
1071             request.setAttribute("pageSelected", "testUniqueComponentIdDecorate1_2.xhtml");
1072             UIViewRoot root = facesContext.getViewRoot();
1073             root.setViewId("/testUniqueComponentIdDecorate1.xhtml");
1074             vdl.buildView(facesContext, root, "/testUniqueComponentIdDecorate1.xhtml");
1075 
1076             
1077             //1. test unique MARK_CREATED id
1078             for (UIComponent child : root.getChildren())
1079             {
1080                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
1081                 String componentId = child.getId();
1082                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
1083                 {
1084                     if ("-C-".equals(((UIOutput)child).getValue()) ||
1085                         "-B-".equals(((UIOutput)child).getValue()) ||
1086                         "-D-".equals(((UIOutput)child).getValue()))
1087                     {
1088                         //This is a different C,B or D, because it the template is different
1089                         //the final component id could be the same or different, but the
1090                         //important here is refreshing algorithm should not mix both 
1091                         Assert.assertTrue(!tagUniqueIdSet.contains(id));
1092                     }
1093                     else
1094                     {
1095                         if (!tagUniqueIdSet.contains(id))
1096                         {
1097                             Assert.fail();
1098                         }
1099                         if (!componentIdSet.contains(componentId))
1100                         {
1101                             Assert.fail();
1102                         }
1103                     }
1104                 }
1105                 else
1106                 {
1107                     if (!tagUniqueIdSet.contains(id))
1108                     {
1109                         Assert.fail();
1110                     }
1111                     if (!componentIdSet.contains(componentId))
1112                     {
1113                         Assert.fail();
1114                     }
1115                 }
1116             }
1117             
1118             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
1119             
1120             viewStateParam = application.getStateManager().getViewState(facesContext);
1121         }
1122         finally
1123         {
1124             tearDownRequest();
1125         }
1126 
1127     }
1128 
1129     @Test
1130     public void testUniqueComponentIdDecorateSaveCondition() throws Exception
1131     {
1132         String viewStateParam = null;
1133         String componentBid = null;
1134         String tagBId = null;
1135         Set<String> tagUniqueIdSet = new HashSet<String>();
1136         Set<String> componentIdSet = new HashSet<String>();
1137         
1138         ((MockRenderKit)renderKit).setResponseStateManager(new HtmlResponseStateManager());
1139         StateUtils.initSecret(servletContext);
1140         servletContext.setAttribute(StateUtils.SERIAL_FACTORY, new DefaultSerialFactory());
1141         try
1142         {
1143             setupRequest();
1144             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
1145             request.setAttribute("pageSelected", "testUniqueComponentIdDecorate1_1.xhtml");
1146             UIViewRoot root = facesContext.getViewRoot();
1147             root.setViewId("/testUniqueComponentIdDecorate1.xhtml");
1148             vdl.buildView(facesContext, root, "/testUniqueComponentIdDecorate1.xhtml");
1149 
1150             
1151             //1. test unique MARK_CREATED id
1152             for (UIComponent child : root.getChildren())
1153             {
1154                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
1155                 if (tagUniqueIdSet.contains(id))
1156                 {
1157                     Assert.fail();
1158                 }
1159                 tagUniqueIdSet.add(id);
1160                 String componentId = child.getId();
1161                 if (componentIdSet.contains(componentId))
1162                 {
1163                     Assert.fail();
1164                 }
1165                 componentIdSet.add(componentId);
1166                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
1167                 {
1168                     if ("-B-".equals(((UIOutput)child).getValue()))
1169                     {
1170                         componentBid = componentId;
1171                         tagBId = id;
1172                         child.getAttributes().put("test", "test");
1173                     }
1174                 }
1175             }
1176             
1177             Assert.assertNotNull(componentBid);
1178             Assert.assertNotNull(tagBId);
1179             
1180             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
1181             
1182             viewStateParam = application.getStateManager().getViewState(facesContext);
1183         }
1184         finally
1185         {
1186             tearDownRequest();
1187         }
1188 
1189         try
1190         {
1191             setupRequest();
1192             facesContext.setCurrentPhaseId(PhaseId.RESTORE_VIEW);
1193             request.setAttribute("pageSelected", "testUniqueComponentIdDecorate1_0.xhtml");
1194             request.addParameter(ResponseStateManager.VIEW_STATE_PARAM, viewStateParam);
1195     
1196             UIViewRoot root = application.getStateManager().restoreView(facesContext, "/testUniqueComponentIdDecorate1.xhtml", RenderKitFactory.HTML_BASIC_RENDER_KIT);
1197 
1198             Assert.assertNotNull(root);
1199             
1200             boolean restoredB = false;
1201             //1. test unique MARK_CREATED id
1202             for (UIComponent child : root.getChildren())
1203             {
1204                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
1205                 String componentId = child.getId();
1206                 
1207                 if (!tagUniqueIdSet.contains(id))
1208                 {
1209                     Assert.fail();
1210                 }
1211                 if (!componentIdSet.contains(componentId))
1212                 {
1213                     Assert.fail();
1214                 }
1215                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
1216                 {
1217                     if ("-B-".equals(((UIOutput)child).getValue()))
1218                     {
1219                         restoredB = true;
1220                         Assert.assertNotNull(child.getAttributes().get("test"));
1221                     }
1222                 }
1223             }
1224             
1225             Assert.assertTrue(restoredB);
1226             
1227             //Now let's refresh the view on render response, to reflect the value on the condition
1228             tagUniqueIdSet.remove(tagBId);
1229             componentIdSet.remove(componentBid);
1230             
1231             //Refresh!
1232             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
1233             vdl.buildView(facesContext, root, "/testUniqueComponentIdDecorate1.xhtml");
1234             
1235             //1. test unique MARK_CREATED id
1236             for (UIComponent child : root.getChildren())
1237             {
1238                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
1239                 String componentId = child.getId();
1240                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput
1241                         && "-C-".equals(((UIOutput)child).getValue()))
1242                 {
1243                     //This is a different C, because it the template is different
1244                     //the final component id could be the same or different, but the
1245                     //important here is refreshing algorithm should not mix both 
1246                     Assert.assertTrue(!tagUniqueIdSet.contains(id));
1247                 }
1248                 else
1249                 {
1250                     if (!tagUniqueIdSet.contains(id))
1251                     {
1252                         Assert.fail();
1253                     }
1254                     if (!componentIdSet.contains(componentId))
1255                     {
1256                         Assert.fail();
1257                     }
1258                 }
1259             }
1260         }
1261         finally
1262         {
1263             tearDownRequest();
1264         }
1265     }
1266 
1267     @Test
1268     public void testUniqueComponentIdChoose() throws Exception
1269     {
1270         String viewStateParam = null;
1271         String componentBid = null;
1272         String tagBId = null;
1273         Set<String> tagUniqueIdSet = new HashSet<String>();
1274         Set<String> componentIdSet = new HashSet<String>();
1275         try
1276         {
1277             setupRequest();
1278             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
1279             request.setAttribute("selectionC", true);
1280             UIViewRoot root = facesContext.getViewRoot();
1281             root.setViewId("/testUniqueComponentIdChoose.xhtml");
1282             vdl.buildView(facesContext, root, "/testUniqueComponentIdChoose.xhtml");
1283 
1284             
1285             //1. test unique MARK_CREATED id
1286             for (UIComponent child : root.getChildren())
1287             {
1288                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
1289                 if (tagUniqueIdSet.contains(id))
1290                 {
1291                     Assert.fail();
1292                 }
1293                 tagUniqueIdSet.add(id);
1294                 String componentId = child.getId();
1295                 if (componentIdSet.contains(componentId))
1296                 {
1297                     Assert.fail();
1298                 }
1299                 componentIdSet.add(componentId);
1300                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
1301                 {
1302                     if ("-C-".equals(((UIOutput)child).getValue()))
1303                     {
1304                         componentBid = componentId;
1305                         tagBId = id;
1306                     }
1307                 }
1308             }
1309             
1310             Assert.assertNotNull(componentBid);
1311             Assert.assertNotNull(tagBId);
1312             
1313             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
1314             
1315             viewStateParam = application.getStateManager().getViewState(facesContext);
1316         }
1317         finally
1318         {
1319             tearDownRequest();
1320         }
1321 
1322         tagUniqueIdSet.remove(tagBId);
1323         componentIdSet.remove(componentBid);
1324 
1325         try
1326         {
1327             setupRequest();
1328             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
1329             request.setAttribute("selectionX", true);
1330             UIViewRoot root = facesContext.getViewRoot();
1331             root.setViewId("/testUniqueComponentIdChoose.xhtml");
1332             vdl.buildView(facesContext, root, "/testUniqueComponentIdChoose.xhtml");
1333 
1334             
1335             //1. test unique MARK_CREATED id
1336             for (UIComponent child : root.getChildren())
1337             {
1338                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
1339                 if (!tagUniqueIdSet.contains(id))
1340                 {
1341                     Assert.fail();
1342                 }
1343                 String componentId = child.getId();
1344                 if (!componentIdSet.contains(componentId))
1345                 {
1346                     Assert.fail();
1347                 }
1348             }
1349             
1350             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
1351             
1352             viewStateParam = application.getStateManager().getViewState(facesContext);
1353         }
1354         finally
1355         {
1356             tearDownRequest();
1357         }
1358 
1359     }
1360 
1361     @Test
1362     public void testUniqueComponentIdChooseSaveCondition() throws Exception
1363     {
1364         String viewStateParam = null;
1365         String componentBid = null;
1366         String tagBId = null;
1367         Set<String> tagUniqueIdSet = new HashSet<String>();
1368         Set<String> componentIdSet = new HashSet<String>();
1369         
1370         ((MockRenderKit)renderKit).setResponseStateManager(new HtmlResponseStateManager());
1371         StateUtils.initSecret(servletContext);
1372         servletContext.setAttribute(StateUtils.SERIAL_FACTORY, new DefaultSerialFactory());
1373         try
1374         {
1375             setupRequest();
1376             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
1377             request.setAttribute("selectionB", true);
1378             UIViewRoot root = facesContext.getViewRoot();
1379             root.setViewId("/testUniqueComponentIdChoose.xhtml");
1380             vdl.buildView(facesContext, root, "/testUniqueComponentIdChoose.xhtml");
1381 
1382             
1383             //1. test unique MARK_CREATED id
1384             for (UIComponent child : root.getChildren())
1385             {
1386                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
1387                 if (tagUniqueIdSet.contains(id))
1388                 {
1389                     Assert.fail();
1390                 }
1391                 tagUniqueIdSet.add(id);
1392                 String componentId = child.getId();
1393                 if (componentIdSet.contains(componentId))
1394                 {
1395                     Assert.fail();
1396                 }
1397                 componentIdSet.add(componentId);
1398                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
1399                 {
1400                     if ("-B-".equals(((UIOutput)child).getValue()))
1401                     {
1402                         componentBid = componentId;
1403                         tagBId = id;
1404                     }
1405                 }
1406             }
1407             
1408             Assert.assertNotNull(componentBid);
1409             Assert.assertNotNull(tagBId);
1410             
1411             application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
1412             
1413             viewStateParam = application.getStateManager().getViewState(facesContext);
1414         }
1415         finally
1416         {
1417             tearDownRequest();
1418         }
1419 
1420         try
1421         {
1422             setupRequest();
1423             facesContext.setCurrentPhaseId(PhaseId.RESTORE_VIEW);
1424             request.setAttribute("selectionX", true);
1425             request.addParameter(ResponseStateManager.VIEW_STATE_PARAM, viewStateParam);
1426     
1427             UIViewRoot root = application.getStateManager().restoreView(facesContext, "/testUniqueComponentIdChoose.xhtml", RenderKitFactory.HTML_BASIC_RENDER_KIT);
1428 
1429             Assert.assertNotNull(root);
1430             
1431             boolean restoredB = false;
1432             //1. test unique MARK_CREATED id
1433             for (UIComponent child : root.getChildren())
1434             {
1435                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
1436                 if (!tagUniqueIdSet.contains(id))
1437                 {
1438                     Assert.fail();
1439                 }
1440                 String componentId = child.getId();
1441                 if (!componentIdSet.contains(componentId))
1442                 {
1443                     Assert.fail();
1444                 }
1445                 if (componentId.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) && child instanceof UIOutput)
1446                 {
1447                     if ("-B-".equals(((UIOutput)child).getValue()))
1448                     {
1449                         restoredB = true;
1450                     }
1451                 }
1452             }
1453             
1454             Assert.assertTrue(restoredB);
1455             
1456             //Now let's refresh the view on render response, to reflect the value on the condition
1457             tagUniqueIdSet.remove(tagBId);
1458             componentIdSet.remove(componentBid);
1459             
1460             //Refresh!
1461             facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
1462             vdl.buildView(facesContext, root, "/testUniqueComponentIdChoose.xhtml");
1463             
1464             //1. test unique MARK_CREATED id
1465             for (UIComponent child : root.getChildren())
1466             {
1467                 String id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
1468                 if (!tagUniqueIdSet.contains(id))
1469                 {
1470                     Assert.fail();
1471                 }
1472                 String componentId = child.getId();
1473                 if (!componentIdSet.contains(componentId))
1474                 {
1475                     Assert.fail();
1476                 }
1477             }
1478         }
1479         finally
1480         {
1481             tearDownRequest();
1482         }
1483     }
1484 
1485 }