001: /*
002: * Copyright 2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package javax.faces.component;
017:
018: import java.util.Iterator;
019:
020: import javax.faces.context.FacesContext;
021:
022: /**
023: * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
024: *
025: * @author Manfred Geiler (latest modification by $Author: mbr $)
026: * @version $Revision: 518919 $ $Date: 2007-03-16 11:21:48 +0100 (Fr, 16 Mrz 2007) $
027: */
028: public class UIForm extends UIComponentBase implements NamingContainer {
029: //private static final Log log = LogFactory.getLog(UIForm.class);
030:
031: private boolean _submitted;
032:
033: private Boolean _prependId;
034:
035: public boolean isSubmitted() {
036: return _submitted;
037: }
038:
039: public void setSubmitted(boolean submitted) {
040: _submitted = submitted;
041: }
042:
043: public void processDecodes(javax.faces.context.FacesContext context) {
044: if (context == null)
045: throw new NullPointerException("context");
046: decode(context);
047: if (!isSubmitted())
048: return;
049: for (Iterator it = getFacetsAndChildren(); it.hasNext();) {
050: UIComponent childOrFacet = (UIComponent) it.next();
051: childOrFacet.processDecodes(context);
052: }
053: }
054:
055: public void processValidators(
056: javax.faces.context.FacesContext context) {
057: if (context == null)
058: throw new NullPointerException("context");
059: // SF issue #1050022: a form used within a datatable will loose it's submitted state
060: // as UIForm is no EditableValueHolder and therefore it's state is not saved/restored by UIData
061: // to restore the submitted state we call decode here again
062: if (!isSubmitted()) {
063: decode(context);
064: }
065: if (!isSubmitted())
066: return;
067: for (Iterator it = getFacetsAndChildren(); it.hasNext();) {
068: UIComponent childOrFacet = (UIComponent) it.next();
069: childOrFacet.processValidators(context);
070: }
071: }
072:
073: public void processUpdates(javax.faces.context.FacesContext context) {
074: if (context == null)
075: throw new NullPointerException("context");
076: // SF issue #1050022: a form used within a datatable will loose it's submitted state
077: // as UIForm is no EditableValueHolder and therefore it's state is not saved/restored by UIData
078: // to restore the submitted state we call decode here again
079: if (!isSubmitted()) {
080: decode(context);
081: }
082: if (!isSubmitted())
083: return;
084: for (Iterator it = getFacetsAndChildren(); it.hasNext();) {
085: UIComponent childOrFacet = (UIComponent) it.next();
086: childOrFacet.processUpdates(context);
087: }
088: }
089:
090: public Object saveState(javax.faces.context.FacesContext context) {
091: Object[] state = new Object[2];
092: state[0] = super .saveState(context);
093: state[1] = _prependId;
094: return state;
095: }
096:
097: @Override
098: public void restoreState(FacesContext context, Object state) {
099: Object[] values = (Object[]) state;
100: super .restoreState(context, values[0]);
101: _prependId = (Boolean) values[1];
102: }
103:
104: //------------------ GENERATED CODE BEGIN (do not modify!) --------------------
105:
106: public static final String COMPONENT_TYPE = "javax.faces.Form";
107: public static final String COMPONENT_FAMILY = "javax.faces.Form";
108: private static final String DEFAULT_RENDERER_TYPE = "javax.faces.Form";
109:
110: public UIForm() {
111: setRendererType(DEFAULT_RENDERER_TYPE);
112: }
113:
114: public String getFamily() {
115: return COMPONENT_FAMILY;
116: }
117:
118: //------------------ GENERATED CODE END ---------------------------------------
119:
120: public String getContainerClientId(FacesContext ctx) {
121: if (isPrependId()) {
122: return super .getContainerClientId(ctx);
123: }
124: UIComponent parentNamingContainer = _ComponentUtils
125: .findParentNamingContainer(this , false);
126: if (parentNamingContainer != null) {
127: return parentNamingContainer.getContainerClientId(ctx);
128: }
129: return null;
130: }
131:
132: public boolean isPrependId() {
133: return getExpressionValue("prependId", _prependId, true);
134: }
135:
136: public void setPrependId(boolean prependId) {
137: _prependId = prependId;
138: }
139:
140: }
|