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 javax.faces.bean.ManagedBean;
22  import javax.faces.bean.RequestScoped;
23  import javax.faces.component.UIOutput;
24  import javax.faces.component.UIPanel;
25  import javax.faces.component.UIViewParameter;
26  import javax.faces.component.html.HtmlPanelGroup;
27  import javax.faces.context.FacesContext;
28  
29  /**
30   *
31   * @author Leonardo Uribe
32   */
33  @ManagedBean(name="componentBindingBean")
34  @RequestScoped
35  public class ComponentBindingBean
36  {
37      private UIPanel panel;
38      
39      private UIViewParameter viewParam;
40      
41      public UIPanel getPanel()
42      {
43          if (panel == null)
44          {
45              panel = new HtmlPanelGroup();
46              if (FacesContext.getCurrentInstance().isPostback())
47              {
48                  // Just try to mess the binding. In theory this does
49                  // not have effect, because the binding with children
50                  // or facets should be restored fully.
51                  UIOutput out2 = new UIOutput();
52                  out2.setValue("hello2");
53                  panel.getChildren().add(out2);
54              }
55              UIOutput out = new UIOutput();
56              out.setValue("hello1");
57              panel.getChildren().add(out);
58              if (!FacesContext.getCurrentInstance().isPostback())
59              {
60                  // Store something into the state
61                  panel.getAttributes().put("attr1", "value1");
62                  panel.getChildren().get(0).getAttributes().put("attr2", "value2");
63              }
64              else
65              {
66                  //Try to mess the state, in theory it should not have effect
67                  panel.getAttributes().remove("attr1");
68                  panel.getChildren().get(0).getAttributes().remove("attr2");
69              }
70          }
71          return panel;
72      }
73      
74      public void setPanel(UIPanel panel)
75      {
76          this.panel = panel;
77      }
78  
79      /**
80       * @return the viewParam
81       */
82      public UIViewParameter getViewParam()
83      {
84          return viewParam;
85      }
86  
87      /**
88       * @param viewParam the viewParam to set
89       */
90      public void setViewParam(UIViewParameter viewParam)
91      {
92          this.viewParam = viewParam;
93      }
94  }