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  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  public interface EditableValueHolder extends ValueHolder
53  {
54      /**
55       * Get an object representing the most recent raw user input received for this component.
56       * <p>
57       * This is non-null only between <code>decode</code> and <code>validate</code> phases, or when validation for the
58       * component has not succeeded. Once conversion and validation has succeeded, the (converted) value is stored in the
59       * local "value" property of this component, and the submitted value is reset to null.
60       */
61      public Object getSubmittedValue();
62  
63      /**
64       * Invoked during the "decode" phase of processing to inform this component what data was received from the user.
65       * <p>
66       * In many cases the submitted value is a plain string extracted from the current servlet request object.
67       * <p>
68       * In cases where a component is rendered as multiple input components (eg a calendar control with separate
69       * day/month/year fields), the submittedValue may be some custom object wrapping the data. However the provided
70       * object <i>must</i> be able to represent all possible user input values, not just valid ones.
71       */
72      public void setSubmittedValue(Object submittedValue);
73  
74      /**
75       * Determine whether the value member variable of this component has been set from the converted and validated
76       * "submitted value". This property is needed because EditableValueHolder components need to distinguish between the
77       * value local <i>member</i> and the value <i>property</i> (which may involve a value-binding to the user model).
78       */
79      public boolean isLocalValueSet();
80  
81      /**
82       * Specify the return value of method isLocalValueSet. This is called after the local value member has been set from
83       * the converted and validated "submitted value". It is cleared after that value has been pushed to the user model
84       * via the value-binding named "value".
85       */
86      public void setLocalValueSet(boolean localValueSet);
87  
88      /**
89       * This returns false if validation has been run for this component and has failed.
90       * <p>
91       * It is also set to false if the validated value could not be passed to the model during the update model phase.
92       * <p>
93       * All input components are marked as valid during the "restore view" phase, so this will return true for components
94       * whose validation has not been executed.
95       */
96      public boolean isValid();
97  
98      public void setValid(boolean valid);
99  
100     /**
101      * Return true if this component must have a non-empty submitted value.
102      * <p>
103      * Note that even when a component is "required", it is not an error for some form to be submitted which does not
104      * contain the component. It is only an error when the form submitted does contain the component, but there is no
105      * data for the component in that request. A "submitted value" of null is set during the "decode" step to represent
106      * the case where the request map has no entry corresponding to this component's id. When the decode step finds an
107      * entry in the request, but the corresponding value represents "no data" (eg an empty string for a text input
108      * field) then some special non-null value must be set for the "submitted value"; validation for "required" fields
109      * must then check for that.
110      */
111     public boolean isRequired();
112 
113     /**
114      * Set to true to cause validation failure when a form containing this component is submitted and there is no value
115      * selected for this component.
116      */
117     public void setRequired(boolean required);
118 
119     /**
120      * When true, the validation step for this component will also invoke any associated actionListeners. Typically such
121      * listeners will call renderResponse, causing the rendering phase to begin immediately (including possible
122      * navigation) without performing validation on any following components.
123      */
124     public boolean isImmediate();
125 
126     public void setImmediate(boolean immediate);
127 
128     /**
129      * Get the single validator defined directly on this component.
130      * <p>
131      * In addition to this validator, there may be a list of validators associated with this component.
132      * <p>
133      * This validator is executed after all validators in the validator list.
134      * 
135      * @deprecated Use getValidators() instead.
136      */
137     public MethodBinding getValidator();
138 
139     /**
140      * @deprecated Use addValidator(MethodExpressionValidaotr) instead.
141      */
142     public void setValidator(javax.faces.el.MethodBinding validatorBinding);
143 
144     /**
145      * Get the single value-change defined directly on this component.
146      * <p>
147      * In addition to this listener, there may be a list of listeners associated with this component.
148      * <p>
149      * This listeners is executed after all listeners in the list.
150      * 
151      * @deprecated Use getValueChangeLIsteners() instead.
152      */
153     public MethodBinding getValueChangeListener();
154 
155     /**
156      * @deprecated use addValueChangeListener(MethodExpressionValueChangeListener) instead.
157      */
158     public void setValueChangeListener(MethodBinding valueChangeMethod);
159 
160     public void addValidator(Validator validator);
161 
162     public Validator[] getValidators();
163 
164     public void removeValidator(Validator validator);
165 
166     public void addValueChangeListener(ValueChangeListener listener);
167 
168     public ValueChangeListener[] getValueChangeListeners();
169 
170     public void removeValueChangeListener(ValueChangeListener listener);
171 
172     /**
173      * Convenience method to reset this component's value to an uninitialized state, by resetting the local value and
174      * submitted values to null (ensuring that {@link #isLocalValueSet} is false), and setting "valid" to true.
175      * 
176      * @since 2.0
177      */
178     public void resetValue();
179 
180 }