javax.faces.component

Class UIInput

  • All Implemented Interfaces:
    EventListener, EditableValueHolder, PartialStateHolder, StateHolder, TransientStateHolder, ValueHolder, ComponentSystemEventListener, FacesListener, SystemEventListenerHolder
    Direct Known Subclasses:
    HtmlInputFile, HtmlInputHidden, HtmlInputSecret, HtmlInputText, HtmlInputTextarea, UISelectBoolean, UISelectMany, UISelectOne, UIViewParameter

    public class UIInput
    extends UIOutput
    implements EditableValueHolder

    UIInput is a UIComponent that represents a component that both displays output to the user (like UIOutput components do) and processes request parameters on the subsequent request that need to be decoded. There are no restrictions on the data type of the local value, or the object referenced by the value binding expression (if any); however, individual Renderers will generally impose restrictions on the type of data they know how to display.

    During the Apply Request Values phase of the request processing lifecycle, the decoded value of this component, usually but not necessarily a String, must be stored - but not yet converted - using setSubmittedValue(). If the component wishes to indicate that no particular value was submitted, it can either do nothing, or set the submitted value to null.

    By default, during the Process Validators phase of the request processing lifecycle, the submitted value will be converted to a typesafe object, and, if validation succeeds, stored as a local value using setValue(). However, if the immediate property is set to true, this processing will occur instead at the end of the Apply Request Values phase.

    During the Render Response phase of the request processing lifecycle, conversion for output occurs as for UIOutput.

    When the validate() method of this UIInput detects that a value change has actually occurred, and that all validations have been successfully passed, it will queue a ValueChangeEvent. Later on, the broadcast() method will ensure that this event is broadcast to all interested listeners. This event will be delivered by default in the Process Validators phase, but can be delivered instead during Apply Request Values if the immediate property is set to true. If the validation fails, the implementation must call FacesContext.validationFailed().

    By default, the rendererType property must be set to "Text". This value can be changed by calling the setRendererType() method.

Throws:
ConverterException
  • validateValue

    protected void validateValue(FacesContext context,
                                 Object newValue)

    Set the "valid" property according to the below algorithm.

    • If the valid property on this component is still true, and the required property is also true, ensure that the local value is not empty (where "empty" is defined as null or a zero-length String). If the local value is empty:

    • Otherwise, if the valid property on this component is still true, take the following action to determine if validation of this component should proceed.

      • If the value is not empty, validation should proceed.

      • If the value is empty, but the system has been directed to validate empty fields, validation should proceed. The implementation must obtain the init parameter Map from the ExternalContext and inspect the value for the key given by the value of the symbolic constant VALIDATE_EMPTY_FIELDS_PARAM_NAME. If there is no value under that key, use the same key and look in the application map from the ExternalContext. If the value is null or equal to the string “auto” (without the quotes) take appropriate action to determine if Bean Validation is present in the runtime environment. If not, validation should not proceed. If so, validation should proceed. If the value is equal (ignoring case) to “true” (without the quotes) validation should proceed. Otherwise, validation should not proceed.

      • If the above determination indicates that validation should proceed, call the validate() method of each Validator registered for this UIInput, followed by the method pointed at by the validatorBinding property (if any). If any of these validators or the method throws a ValidatorException, catch the exception, add its message (if any) to the FacesContext, and set the valid property of this component to false.

  • compareValues

    protected boolean compareValues(Object previous,
                                    Object value)

    Return true if the new value is different from the previous value. First compare the two values by passing value to the equals method on argument previous. If that method returns true, return true. If that method returns false, and both arguments implement java.lang.Comparable, compare the two values by passing value to the compareTo method on argument previous. Return true if this method returns 0, false otherwise.

    Parameters:
    previous - old value of this component (if any)
    value - new value of this component (if any)
  • isEmpty

    public static boolean isEmpty(Object value)
  • saveState

    public Object saveState(FacesContext context)
    Description copied from interface: StateHolder

    Gets the state of the instance as a Serializable Object.

    If the class that implements this interface has references to instances that implement StateHolder (such as a UIComponent with event handlers, validators, etc.) this method must call the StateHolder.saveState(javax.faces.context.FacesContext) method on all those instances as well. This method must not save the state of children and facets. That is done via the StateManager

    This method must not alter the state of the implementing object. In other words, after executing this code:

     Object state = component.saveState(facesContext);
     

    component should be the same as before executing it.

    The return from this method must be Serializable

    Specified by:
    saveState in interface StateHolder
    Overrides:
    saveState in class UIOutput