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 javax.faces.el.MethodBinding;
019: import javax.faces.event.ValueChangeListener;
020: import javax.faces.validator.Validator;
021:
022: /**
023: * Defines the methods required for a component whose value can be
024: * modified by the user.
025: * <p>
026: * When a component implementing this interface is rendered, the value
027: * output is (in order):
028: * <ul>
029: * <li>The "submitted value" if non-null.
030: * <li>The component's "local value" if non-null.
031: * <li>The result of evaluating the value-binding expression with name
032: * "value" for this component.
033: * </ul>
034: * <p>
035: * Rendering the submitted value if non-null allows a component to redisplay
036: * a user-provided value when validation fails for the component. The
037: * submitted value is usually just the plain string extracted from the
038: * servlet request. During successful validation of the component, the
039: * submitted value is converted to an appropriate datatype, and stored as
040: * the component's "local value", and then the "submitted value" is
041: * immediately reset to null.
042: * <p>
043: * Rendering the "local value" if non-null allows a component to redisplay
044: * a page when validation fails for some other component; the model can't
045: * be updated unless <i>all</i> components have passed validation. This
046: * also allows components to work without a defined "value" value-binding
047: * expression. When all components validate, the update model phase runs;
048: * all components with "value" value-bindings store the "local value" into
049: * the specified property then reset their local value to null.
050: * <p>
051: * Rendering the value-binding expression named "value" allows components
052: * to display data from the user's model classes. This is the most common
053: * way a component's renderer obtains the value to display.
054: *
055: * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a> for more.
056: *
057: * @author Manfred Geiler (latest modification by $Author: mbr $)
058: * @version $Revision: 512227 $ $Date: 2007-02-27 13:25:16 +0100 (Di, 27 Feb 2007) $
059: */
060: public interface EditableValueHolder extends ValueHolder {
061: /**
062: * Get an object representing the most recent raw user input
063: * received for this component.
064: * <p>
065: * This is non-null only between <code>decode</code> and
066: * <code>validate</code> phases, or when validation for the
067: * component has not succeeded. Once conversion and validation has
068: * succeeded, the (converted) value is stored in the local "value"
069: * property of this component, and the submitted value is reset to null.
070: */
071: public Object getSubmittedValue();
072:
073: /**
074: * Invoked during the "decode" phase of processing to inform this
075: * component what data was received from the user.
076: * <p>
077: * In many cases the submitted value is a plain string extracted
078: * from the current servlet request object.
079: * <p>
080: * In cases where a component is rendered as multiple input components
081: * (eg a calendar control with separate day/month/year fields), the
082: * submittedValue may be some custom object wrapping the data.
083: * However the provided object <i>must</i> be able to represent all
084: * possible user input values, not just valid ones.
085: */
086: public void setSubmittedValue(Object submittedValue);
087:
088: /**
089: * Determine whether the value member variable of this component has
090: * been set from the converted and validated "submitted value". This
091: * property is needed because EditableValueHolder components need
092: * to distinguish between the value local <i>member</i> and the
093: * value <i>property</i> (which may involve a value-binding to the
094: * user model).
095: */
096: public boolean isLocalValueSet();
097:
098: /**
099: * Specify the return value of method isLocalValueSet. This is called
100: * after the local value member has been set from the converted and
101: * validated "submitted value". It is cleared after that value has
102: * been pushed to the user model via the value-binding named "value".
103: */
104: public void setLocalValueSet(boolean localValueSet);
105:
106: /**
107: * This returns false if validation has been run for this component
108: * and has failed.
109: * <p>
110: * It is also set to false if the validated value could not be passed
111: * to the model during the update model phase.
112: * <p>
113: * All input components are marked as valid during the "restore view"
114: * phase, so this will return true for components whose validation
115: * has not been executed.
116: */
117: public boolean isValid();
118:
119: public void setValid(boolean valid);
120:
121: /**
122: * Return true if this component must have a non-empty submitted
123: * value.
124: * <p>
125: * Note that even when a component is "required", it is not an
126: * error for some form to be submitted which does not contain
127: * the component. It is only an error when the form submitted
128: * does contain the component, but there is no data for the
129: * component in that request. A "submitted value" of null is
130: * set during the "decode" step to represent the case where
131: * the request map has no entry corresponding to this component's
132: * id. When the decode step finds an entry in the request, but
133: * the corresponding value represents "no data" (eg an empty
134: * string for a text input field) then some special non-null
135: * value must be set for the "submitted value"; validation
136: * for "required" fields must then check for that.
137: */
138: public boolean isRequired();
139:
140: /**
141: * Set to true to cause validation failure when a form
142: * containing this component is submitted and there is no
143: * value selected for this component.
144: */
145: public void setRequired(boolean required);
146:
147: /**
148: * When true, the validation step for this component will also
149: * invoke any associated actionListeners. Typically such listeners
150: * will call renderResponse, causing the rendering phase to begin
151: * immediately (including possible navigation) without performing
152: * validation on any following components.
153: */
154: public boolean isImmediate();
155:
156: public void setImmediate(boolean immediate);
157:
158: /**
159: * Get the single validator defined directly on this component.
160: * <p>
161: * In addition to this validator, there may be a list of validators
162: * associated with this component.
163: * <p>
164: * This validator is executed after all validators in the validator list.
165: *
166: * @deprecated Use getValidators() instead.
167: */
168: public MethodBinding getValidator();
169:
170: /**
171: * @deprecated Use addValidator(MethodExpressionValidaotr) instead.
172: */
173: public void setValidator(
174: javax.faces.el.MethodBinding validatorBinding);
175:
176: /**
177: * Get the single value-change defined directly on this component.
178: * <p>
179: * In addition to this listener, there may be a list of listeners
180: * associated with this component.
181: * <p>
182: * This listeners is executed after all listeners in the list.
183: *
184: * @deprecated Use getValueChangeLIsteners() instead.
185: */
186: public MethodBinding getValueChangeListener();
187:
188: /**
189: * @deprecated use addValueChangeListener(MethodExpressionValueChangeListener) instead.
190: */
191: public void setValueChangeListener(MethodBinding valueChangeMethod);
192:
193: public void addValidator(Validator validator);
194:
195: public Validator[] getValidators();
196:
197: public void removeValidator(Validator validator);
198:
199: public void addValueChangeListener(ValueChangeListener listener);
200:
201: public ValueChangeListener[] getValueChangeListeners();
202:
203: public void removeValueChangeListener(ValueChangeListener listener);
204: }
|