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.pss.acid.managed;
20  
21  import java.util.Random;
22  import javax.faces.bean.ManagedBean;
23  import javax.faces.bean.RequestScoped;
24  import javax.faces.component.UIOutput;
25  import javax.faces.component.UIPanel;
26  import javax.faces.component.html.HtmlPanelGroup;
27  
28  /**
29   *
30   */
31  @ManagedBean(name="componentBindingFormBean")
32  @RequestScoped
33  public class ComponentBindingFormBean
34  {
35      private boolean rebuildDone = false;
36      
37      private UIPanel panel;
38      
39      public UIPanel getPanel()
40      {
41          if (!rebuildDone)
42          {
43              rebuildForm();
44          }
45          return panel;
46      }
47      
48      public void rebuildForm()
49      {
50          if (panel == null)
51          {
52              panel = new HtmlPanelGroup();
53              //panel.setTransient(true);
54              panel.setId("formRoot");            
55          }
56          
57           // Clear the existing tree. 
58          panel.getChildren().clear();
59              
60          // Start building the new component tree with formRoot as parent.
61          Random random = new Random() ;
62          int n = random.nextInt(9)+1;
63  
64          for(int i = 0; i < n; i++)
65          {
66              UIOutput input = new UIOutput();
67              input.setId("input_"+i);
68              panel.getChildren().add(input);
69          }
70          
71          this.rebuildDone = true;
72      }
73      
74      public void forceRebuild()
75      {
76          rebuildForm();
77      }
78      
79      public void setPanel(UIPanel panel)
80      {
81          this.panel = panel;
82      }
83  }