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.pool;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  import javax.faces.bean.ManagedBean;
24  import javax.faces.bean.RequestScoped;
25  import javax.faces.component.UIComponent;
26  import javax.faces.component.UIOutput;
27  import javax.faces.component.html.HtmlOutputText;
28  import javax.faces.component.html.HtmlPanelGroup;
29  import javax.faces.context.FacesContext;
30  import javax.faces.view.ViewDeclarationLanguage;
31  
32  /**
33   *
34   * @author lu4242
35   */
36  @ManagedBean(name="simpleRequestBean")
37  @RequestScoped
38  public class SimpleRequestBean
39  {
40      // Simple binding
41      private HtmlPanelGroup panel1;
42      
43      // Simple binding with children
44      private HtmlPanelGroup panel2;
45      
46      // Simple binding with children and createComponent
47      private HtmlPanelGroup panel3;
48      
49      // Simple binding with children and createComponent composite
50      private HtmlPanelGroup panel4;
51      
52      public void validateField(FacesContext context, UIComponent component, Object value)
53      {
54          //Dummy method to check if the view pool works or not
55      }
56      
57      public HtmlPanelGroup getPanel1()
58      {
59          if (panel1 == null)
60          {
61              panel1 = new HtmlPanelGroup();
62          }
63          return panel1;
64      }
65  
66      /**
67       * @param panel1 the panel1 to set
68       */
69      public void setPanel1(HtmlPanelGroup panel1)
70      {
71          this.panel1 = panel1;
72      }
73      
74      public HtmlPanelGroup getPanel2()
75      {
76          if (panel2 == null)
77          {
78              panel2 = new HtmlPanelGroup();
79              UIOutput text = new HtmlOutputText();
80              text.setValue("added component through binding");
81              panel2.getChildren().add(text);
82          }
83          return panel2;
84      }
85  
86      /**
87       * @param panel1 the panel1 to set
88       */
89      public void setPanel2(HtmlPanelGroup panel2)
90      {
91          this.panel2 = panel2;
92      }
93  
94      /**
95       * @return the panel3
96       */
97      public HtmlPanelGroup getPanel3()
98      {
99          if (panel3 == null)
100         {
101             FacesContext facesContext = FacesContext.getCurrentInstance();
102             
103             ViewDeclarationLanguage vdl = facesContext.getApplication().
104                 getViewHandler().getViewDeclarationLanguage(
105                     facesContext, facesContext.getViewRoot().getViewId());
106             
107             panel3 = new HtmlPanelGroup();
108             Map<String, Object> attributes = new HashMap<String, Object>();
109             attributes.put("src", "/staticPageBinding3_1.xhtml");
110             UIComponent component = vdl.createComponent(facesContext, 
111                 "http://java.sun.com/jsf/facelets", 
112                 "include", attributes);
113             panel3.getChildren().add(component);
114 
115         }
116         return panel3;
117     }
118 
119     /**
120      * @param panel3 the panel3 to set
121      */
122     public void setPanel3(HtmlPanelGroup panel3)
123     {
124         this.panel3 = panel3;
125     }
126 
127     /**
128      * @return the panel4
129      */
130     public HtmlPanelGroup getPanel4()
131     {
132         if (panel4 == null)
133         {
134             FacesContext facesContext = FacesContext.getCurrentInstance();
135             
136             ViewDeclarationLanguage vdl = facesContext.getApplication().
137                 getViewHandler().getViewDeclarationLanguage(
138                     facesContext, facesContext.getViewRoot().getViewId());
139             
140             panel4 = new HtmlPanelGroup();
141 
142             Map<String, Object> attributes = new HashMap<String, Object>();
143             UIComponent cc = vdl.createComponent(facesContext, 
144                 "http://java.sun.com/jsf/composite/testComposite", 
145                 "dynComp_1", attributes);
146             UIOutput text = (UIOutput) facesContext.getApplication().
147                 createComponent(UIOutput.COMPONENT_TYPE);
148             text.setValue("Dynamically added header");
149             cc.getFacets().put("header", text);
150             panel4.getChildren().add(cc);            
151         }
152         return panel4;
153     }
154 
155     /**
156      * @param panel4 the panel4 to set
157      */
158     public void setPanel4(HtmlPanelGroup panel4)
159     {
160         this.panel4 = panel4;
161     }
162 }