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 package javax.faces.component;
20
21 import javax.faces.el.MethodBinding;
22 import javax.faces.event.ValueChangeListener;
23 import javax.faces.validator.Validator;
24
25 /**
26 * Defines the methods required for a component whose value can be modified by the user.
27 * <p>
28 * When a component implementing this interface is rendered, the value output is (in order):
29 * <ul>
30 * <li>The "submitted value" if non-null.
31 * <li>The component's "local value" if non-null.
32 * <li>The result of evaluating the value-binding expression with name "value" for this component.
33 * </ul>
34 * <p>
35 * Rendering the submitted value if non-null allows a component to redisplay a user-provided value when validation fails
36 * for the component. The submitted value is usually just the plain string extracted from the servlet request. During
37 * successful validation of the component, the submitted value is converted to an appropriate datatype, and stored as
38 * the component's "local value", and then the "submitted value" is immediately reset to null.
39 * <p>
40 * Rendering the "local value" if non-null allows a component to redisplay a page when validation fails for some other
41 * component; the model can't be updated unless <i>all</i> components have passed validation. This also allows
42 * components to work without a defined "value" value-binding expression. When all components validate, the update model
43 * phase runs; all components with "value" value-bindings store the "local value" into the specified property then reset
44 * their local value to null.
45 * <p>
46 * Rendering the value-binding expression named "value" allows components to display data from the user's model classes.
47 * This is the most common way a component's renderer obtains the value to display.
48 *
49 * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a> for
50 * more.
51 *
52 * @author Manfred Geiler (latest modification by $Author: bommel $)
53 * @version $Revision: 1187701 $ $Date: 2011-10-22 07:21:54 -0500 (Sat, 22 Oct 2011) $
54 */
55 public interface EditableValueHolder extends ValueHolder
56 {
57 /**
58 * Get an object representing the most recent raw user input received for this component.
59 * <p>
60 * This is non-null only between <code>decode</code> and <code>validate</code> phases, or when validation for the
61 * component has not succeeded. Once conversion and validation has succeeded, the (converted) value is stored in the
62 * local "value" property of this component, and the submitted value is reset to null.
63 */
64 public Object getSubmittedValue();
65
66 /**
67 * Invoked during the "decode" phase of processing to inform this component what data was received from the user.
68 * <p>
69 * In many cases the submitted value is a plain string extracted from the current servlet request object.
70 * <p>
71 * In cases where a component is rendered as multiple input components (eg a calendar control with separate
72 * day/month/year fields), the submittedValue may be some custom object wrapping the data. However the provided
73 * object <i>must</i> be able to represent all possible user input values, not just valid ones.
74 */
75 public void setSubmittedValue(Object submittedValue);
76
77 /**
78 * Determine whether the value member variable of this component has been set from the converted and validated
79 * "submitted value". This property is needed because EditableValueHolder components need to distinguish between the
80 * value local <i>member</i> and the value <i>property</i> (which may involve a value-binding to the user model).
81 */
82 public boolean isLocalValueSet();
83
84 /**
85 * Specify the return value of method isLocalValueSet. This is called after the local value member has been set from
86 * the converted and validated "submitted value". It is cleared after that value has been pushed to the user model
87 * via the value-binding named "value".
88 */
89 public void setLocalValueSet(boolean localValueSet);
90
91 /**
92 * This returns false if validation has been run for this component and has failed.
93 * <p>
94 * It is also set to false if the validated value could not be passed to the model during the update model phase.
95 * <p>
96 * All input components are marked as valid during the "restore view" phase, so this will return true for components
97 * whose validation has not been executed.
98 */
99 public boolean isValid();
100
101 public void setValid(boolean valid);
102
103 /**
104 * Return true if this component must have a non-empty submitted value.
105 * <p>
106 * Note that even when a component is "required", it is not an error for some form to be submitted which does not
107 * contain the component. It is only an error when the form submitted does contain the component, but there is no
108 * data for the component in that request. A "submitted value" of null is set during the "decode" step to represent
109 * the case where the request map has no entry corresponding to this component's id. When the decode step finds an
110 * entry in the request, but the corresponding value represents "no data" (eg an empty string for a text input
111 * field) then some special non-null value must be set for the "submitted value"; validation for "required" fields
112 * must then check for that.
113 */
114 public boolean isRequired();
115
116 /**
117 * Set to true to cause validation failure when a form containing this component is submitted and there is no value
118 * selected for this component.
119 */
120 public void setRequired(boolean required);
121
122 /**
123 * When true, the validation step for this component will also invoke any associated actionListeners. Typically such
124 * listeners will call renderResponse, causing the rendering phase to begin immediately (including possible
125 * navigation) without performing validation on any following components.
126 */
127 public boolean isImmediate();
128
129 public void setImmediate(boolean immediate);
130
131 /**
132 * Get the single validator defined directly on this component.
133 * <p>
134 * In addition to this validator, there may be a list of validators associated with this component.
135 * <p>
136 * This validator is executed after all validators in the validator list.
137 *
138 * @deprecated Use getValidators() instead.
139 */
140 public MethodBinding getValidator();
141
142 /**
143 * @deprecated Use addValidator(MethodExpressionValidaotr) instead.
144 */
145 public void setValidator(javax.faces.el.MethodBinding validatorBinding);
146
147 /**
148 * Get the single value-change defined directly on this component.
149 * <p>
150 * In addition to this listener, there may be a list of listeners associated with this component.
151 * <p>
152 * This listeners is executed after all listeners in the list.
153 *
154 * @deprecated Use getValueChangeLIsteners() instead.
155 */
156 public MethodBinding getValueChangeListener();
157
158 /**
159 * @deprecated use addValueChangeListener(MethodExpressionValueChangeListener) instead.
160 */
161 public void setValueChangeListener(MethodBinding valueChangeMethod);
162
163 public void addValidator(Validator validator);
164
165 public Validator[] getValidators();
166
167 public void removeValidator(Validator validator);
168
169 public void addValueChangeListener(ValueChangeListener listener);
170
171 public ValueChangeListener[] getValueChangeListeners();
172
173 public void removeValueChangeListener(ValueChangeListener listener);
174
175 /**
176 * Convenience method to reset this component's value to an uninitialized state, by resetting the local value and
177 * submitted values to null (ensuring that {@link #isLocalValueSet} is false), and setting "valid" to true.
178 *
179 * @since 2.0
180 */
181 public void resetValue();
182
183 }