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  
20  package org.apache.myfaces.tobago.internal.component;
21  
22  import org.apache.myfaces.tobago.util.AjaxUtils;
23  import org.apache.myfaces.tobago.util.ComponentUtils;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  import javax.faces.component.UIComponent;
28  import javax.faces.component.UIForm;
29  import javax.faces.context.FacesContext;
30  import java.util.Iterator;
31  
32  public abstract class AbstractUIForm extends UIForm {
33  
34    private static final Logger LOG = LoggerFactory.getLogger(AbstractUIForm.class);
35  
36    public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Form";
37  
38    @Override
39    public void processDecodes(final FacesContext facesContext) {
40  
41      // Process this component first
42      // to know the active actionId
43      // for the following children
44      decode(facesContext);
45  
46      final Iterator kids = getFacetsAndChildren();
47      while (kids.hasNext()) {
48        final UIComponent kid = (UIComponent) kids.next();
49        kid.processDecodes(facesContext);
50      }
51    }
52  
53    @Override
54    public void setSubmitted(final boolean b) {
55      super.setSubmitted(b);
56  
57      // set submitted for all subforms
58      for (final AbstractUIForm subForm : ComponentUtils.findSubForms(this)) {
59        subForm.setSubmitted(b);
60      }
61    }
62  
63    @Override
64    public void processValidators(final FacesContext facesContext) {
65      // if we're not the submitted form, only process subforms.
66      if (LOG.isDebugEnabled()) {
67        LOG.debug("processValidators for form: {}", getClientId(facesContext));
68      }
69      if (isSubmitted() || AjaxUtils.isAjaxRequest(facesContext)) {
70        // Process all facets and children of this component
71        final Iterator kids = getFacetsAndChildren();
72        while (kids.hasNext()) {
73          final UIComponent kid = (UIComponent) kids.next();
74          kid.processValidators(facesContext);
75        }
76      } else {
77        for (final AbstractUIForm subForm : ComponentUtils.findSubForms(this)) {
78          subForm.processValidators(facesContext);
79        }
80      }
81    }
82  
83    @Override
84    public void processUpdates(final FacesContext facesContext) {
85      // if we're not the submitted form, only process subforms.
86      if (LOG.isDebugEnabled()) {
87        LOG.debug("processUpdates for form: {}", getClientId(facesContext));
88      }
89      if (isSubmitted() || AjaxUtils.isAjaxRequest(facesContext)) {
90        // Process all facets and children of this component
91        final Iterator kids = getFacetsAndChildren();
92        while (kids.hasNext()) {
93          final UIComponent kid = (UIComponent) kids.next();
94          kid.processUpdates(facesContext);
95        }
96      } else {
97        for (final AbstractUIForm subForm : ComponentUtils.findSubForms(this)) {
98          subForm.processUpdates(facesContext);
99        }
100     }
101   }
102 }