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