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.tag.jsf;
20  
21  import java.io.Serializable;
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import javax.faces.component.StateHolder;
26  import javax.faces.component.UIComponentBase;
27  import javax.faces.context.FacesContext;
28  
29  public class FaceletState implements StateHolder, Serializable
30  {
31      /**
32       * 
33       */
34      private static final long serialVersionUID = -7823771271935942737L;
35      
36      public Map<String, Object> stateMap;
37      
38      public Object getState(String key)
39      {
40          if(stateMap == null)
41          {
42              return null;
43          }
44          return stateMap.get(key);
45      }
46      
47      public Object putState(String key, Object value)
48      {
49          if (stateMap == null)
50          {
51              stateMap = new HashMap<String, Object>();
52          }
53          return stateMap.put(key, value);
54      }
55      
56  
57      public Object saveState(FacesContext context)
58      {
59          if (stateMap != null)
60          {
61              return UIComponentBase.saveAttachedState(context, stateMap);
62          }
63          return null;
64      }
65  
66      @SuppressWarnings("unchecked")
67      public void restoreState(FacesContext context, Object state)
68      {
69          if (state == null)
70          {
71              stateMap = null;
72          }
73          else
74          {
75              stateMap = (Map<String,Object>) UIComponentBase.restoreAttachedState(context, state);
76          }
77      }
78  
79      public boolean isTransient()
80      {
81          return false;
82      }
83  
84      public void setTransient(boolean newTransientValue)
85      {
86      }
87  
88  }