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 javax.faces.component;
20  
21  import java.util.Iterator;
22  
23  import javax.faces.context.FacesContext;
24  
25  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
26  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
27  
28  
29  /**
30   * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
31   *
32   * @author Manfred Geiler (latest modification by $Author: lu4242 $)
33   * @version $Revision: 949326 $ $Date: 2010-05-28 19:39:48 -0500 (Fri, 28 May 2010) $
34   */
35  @JSFComponent(type = "javax.faces.Form",
36      family = "javax.faces.Form")
37  public class UIForm
38          extends UIComponentBase
39          implements NamingContainer
40  {
41      //private static final Log log = LogFactory.getLog(UIForm.class);
42  
43      private boolean _submitted;
44      
45      private Boolean _prependId;
46      
47      public boolean isSubmitted()
48      {
49          return _submitted;
50      }
51  
52      public void setSubmitted(boolean submitted)
53      {
54          _submitted = submitted;
55      }
56  
57      public void processDecodes(javax.faces.context.FacesContext context)
58      {
59          if (context == null)
60          {
61              throw new NullPointerException("context");
62          }
63          try
64          {
65              setCachedFacesContext(context);
66              decode(context);
67              if (!isSubmitted()) return;
68              for (Iterator it = getFacetsAndChildren(); it.hasNext(); )
69              {
70                  UIComponent childOrFacet = (UIComponent)it.next();
71                  childOrFacet.processDecodes(context);
72              }
73          }
74          finally
75          {
76              setCachedFacesContext(null);
77          }
78      }
79  
80      public void processValidators(javax.faces.context.FacesContext context)
81      {
82          if (context == null)
83          {
84              throw new NullPointerException("context");
85          }
86          try
87          {
88              setCachedFacesContext(context);
89              // SF issue #1050022: a form used within a datatable will loose it's submitted state
90              // as UIForm is no EditableValueHolder and therefore it's state is not saved/restored by UIData
91              // to restore the submitted state we call decode here again
92              if (!isSubmitted()) {
93                  decode(context);
94              }
95              if (!isSubmitted()) return;
96              for (Iterator it = getFacetsAndChildren(); it.hasNext(); )
97              {
98                  UIComponent childOrFacet = (UIComponent)it.next();
99                  childOrFacet.processValidators(context);
100             }
101         }
102         finally
103         {
104             setCachedFacesContext(null);
105         }
106     }
107 
108     public void processUpdates(javax.faces.context.FacesContext context)
109     {
110         if (context == null)
111         {
112             throw new NullPointerException("context");
113         }
114         try
115         {
116             setCachedFacesContext(context);
117             // SF issue #1050022: a form used within a datatable will loose it's submitted state
118             // as UIForm is no EditableValueHolder and therefore it's state is not saved/restored by UIData
119             // to restore the submitted state we call decode here again
120             if (!isSubmitted()) {
121                 decode(context);
122             }
123             if (!isSubmitted()) return;
124             for (Iterator it = getFacetsAndChildren(); it.hasNext(); )
125             {
126                 UIComponent childOrFacet = (UIComponent)it.next();
127                 childOrFacet.processUpdates(context);
128             }
129         }
130         finally
131         {
132             setCachedFacesContext(null);
133         }
134     }
135 
136     public Object saveState(javax.faces.context.FacesContext context)
137     {
138         Object[] state = new Object[2];
139         state[0] = super.saveState(context);
140         state[1] = _prependId;
141         return state;
142     }
143     
144     @Override
145     public void restoreState(FacesContext context, Object state)
146     {
147         Object[] values = (Object[]) state;
148         super.restoreState(context, values[0]);
149         _prependId = (Boolean) values[1];
150     }
151 
152     //------------------ GENERATED CODE BEGIN (do not modify!) --------------------
153 
154     public static final String COMPONENT_TYPE = "javax.faces.Form";
155     public static final String COMPONENT_FAMILY = "javax.faces.Form";
156     private static final String DEFAULT_RENDERER_TYPE = "javax.faces.Form";
157 
158 
159     public UIForm()
160     {
161         setRendererType(DEFAULT_RENDERER_TYPE);
162     }
163 
164     public String getFamily()
165     {
166         return COMPONENT_FAMILY;
167     }
168 
169 
170     //------------------ GENERATED CODE END ---------------------------------------
171     
172     public String getContainerClientId(FacesContext ctx)
173     {
174         if (isPrependId())
175         {
176             return super.getContainerClientId(ctx);
177         }
178         UIComponent parentNamingContainer = _ComponentUtils.findParentNamingContainer(this, false);
179         if (parentNamingContainer != null)
180         {
181             return parentNamingContainer.getContainerClientId(ctx);
182         }
183         return null;
184     }
185     
186     @JSFProperty(defaultValue = "true")
187     public boolean isPrependId()
188     {
189         return getExpressionValue("prependId", _prependId, true);
190     }
191 
192     public void setPrependId(boolean prependId)
193     {
194         _prependId = prependId;
195     }
196     
197 }