001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package org.apache.myfaces.tobago.component;
021
022 import org.apache.commons.logging.Log;
023 import org.apache.commons.logging.LogFactory;
024
025 import javax.faces.component.UIComponent;
026 import javax.faces.context.FacesContext;
027 import java.util.Iterator;
028
029 public class UIForm extends javax.faces.component.UIForm {
030
031 private static final Log LOG = LogFactory.getLog(UIForm.class);
032
033 public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Form";
034 public static final String SUBMITTED_MARKER = COMPONENT_TYPE + ".InSubmitted";
035
036 public void processDecodes(FacesContext facesContext) {
037
038 // Process this component first
039 // to know the active actionId
040 // for the following childrend
041 decode(facesContext);
042
043 Iterator kids = getFacetsAndChildren();
044 while (kids.hasNext()) {
045 UIComponent kid = (UIComponent) kids.next();
046 kid.processDecodes(facesContext);
047 }
048 }
049
050 public void setSubmitted(boolean b) {
051 super.setSubmitted(b);
052
053 // set submitted for all subforms
054 for (UIForm subForm : ComponentUtil.findSubForms(this)) {
055 subForm.setSubmitted(b);
056 }
057 }
058
059 public void processValidators(FacesContext facesContext) {
060 // if we're not the submitted form, only process subforms.
061 if (LOG.isDebugEnabled()) {
062 LOG.debug("processValidators for form: " + getClientId(facesContext));
063 }
064 if (!isSubmitted()) {
065 for (UIForm subForm : ComponentUtil.findSubForms(this)) {
066 subForm.processValidators(facesContext);
067 }
068 } else {
069 // Process all facets and children of this component
070 Iterator kids = getFacetsAndChildren();
071 while (kids.hasNext()) {
072 UIComponent kid = (UIComponent) kids.next();
073 kid.processValidators(facesContext);
074 }
075 }
076 }
077
078 public void processUpdates(FacesContext facesContext) {
079 // if we're not the submitted form, only process subforms.
080 if (LOG.isDebugEnabled()) {
081 LOG.debug("processUpdates for form: " + getClientId(facesContext));
082 }
083 if (!isSubmitted()) {
084 for (UIForm subForm : ComponentUtil.findSubForms(this)) {
085 subForm.processUpdates(facesContext);
086 }
087 } else {
088 // Process all facets and children of this component
089 Iterator kids = getFacetsAndChildren();
090 while (kids.hasNext()) {
091 UIComponent kid = (UIComponent) kids.next();
092 kid.processUpdates(facesContext);
093 }
094 }
095 }
096 }