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