Class UIInput

  • All Implemented Interfaces:
    java.util.EventListener, EditableValueHolder, PartialStateHolder, StateHolder, TransientStateHolder, ValueHolder, ComponentSystemEventListener, FacesListener, SystemEventListenerHolder
    Direct Known Subclasses:
    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.

    • Field Detail

      • COMPONENT_TYPE

        public static final java.lang.String COMPONENT_TYPE

        The standard component type for this component.

        See Also:
        Constant Field Values
      • COMPONENT_FAMILY

        public static final java.lang.String COMPONENT_FAMILY

        The standard component family for this component.

        See Also:
        Constant Field Values
      • CONVERSION_MESSAGE_ID

        public static final java.lang.String CONVERSION_MESSAGE_ID

        The message identifier of the FacesMessage to be created if a conversion error occurs, and neither the page author nor the ConverterException provides a message.

        See Also:
        Constant Field Values
      • REQUIRED_MESSAGE_ID

        public static final java.lang.String REQUIRED_MESSAGE_ID

        The message identifier of the FacesMessage to be created if a required check fails.

        See Also:
        Constant Field Values
      • UPDATE_MESSAGE_ID

        public static final java.lang.String UPDATE_MESSAGE_ID

        The message identifier of the FacesMessage to be created if a model update error occurs, and the thrown exception has no message.

        See Also:
        Constant Field Values
    • Constructor Detail

      • UIInput

        public UIInput​()

        Create a new UIInput instance with default property values.

    • Method Detail

      • getFamily

        public java.lang.String getFamily​()
        Description copied from class: UIComponent

        Return the identifier of the component family to which this component belongs. This identifier, in conjunction with the value of the rendererType property, may be used to select the appropriate Renderer for this component instance.

        Overrides:
        getFamily in class UIOutput
      • getSubmittedValue

        public java.lang.Object getSubmittedValue​()

        Return the submittedValue value of this UIInput component. This method should only be used by the decode() and validate() method of this component, or its corresponding Renderer.

        Specified by:
        getSubmittedValue in interface EditableValueHolder
      • setSubmittedValue

        public void setSubmittedValue​(java.lang.Object submittedValue)

        Set the submittedValue value of this UIInput component. This method should only be used by the decode() and validate() method of this component, or its corresponding Renderer.

        Specified by:
        setSubmittedValue in interface EditableValueHolder
        Parameters:
        submittedValue - The new submitted value
      • getValue

        public java.lang.Object getValue​()

        If there is a local value, return it, otherwise return the result of calling super.getVaue().

        Specified by:
        getValue in interface ValueHolder
        Overrides:
        getValue in class UIOutput
        Since:
        2.2
      • isLocalValueSet

        public boolean isLocalValueSet​()
        Return the "local value set" state for this component. Calls to setValue() automatically reset this property to true.
        Specified by:
        isLocalValueSet in interface EditableValueHolder
      • setLocalValueSet

        public void setLocalValueSet​(boolean localValueSet)
        Sets the "local value set" state for this component.
        Specified by:
        setLocalValueSet in interface EditableValueHolder
      • isRequired

        public boolean isRequired​()

        Return the "required field" state for this component.

        Specified by:
        isRequired in interface EditableValueHolder
      • setRequiredMessage

        public void setRequiredMessage​(java.lang.String message)

        Override any ValueExpression set for the "requiredMessage" with the literal argument provided to this method. Subsequent calls to getRequiredMessage() will return this value;

        Parameters:
        message - the literal message value to be displayed in the event the user hasn't supplied a value and one is required.
      • setConverterMessage

        public void setConverterMessage​(java.lang.String message)

        Override any ValueExpression set for the "converterMessage" with the literal argument provided to this method. Subsequent calls to getConverterMessage() will return this value;

        Parameters:
        message - the literal message value to be displayed in the event conversion fails.
      • setValidatorMessage

        public void setValidatorMessage​(java.lang.String message)

        Override any ValueExpression set for the "validatorMessage" with the literal argument provided to this method. Subsequent calls to getValidatorMessage() will return this value;

        Parameters:
        message - the literal message value to be displayed in the event validation fails.
      • isValid

        public boolean isValid​()
        Description copied from interface: EditableValueHolder

        Return a flag indicating whether the local value of this component is valid (no conversion error has occurred).

        Specified by:
        isValid in interface EditableValueHolder
      • setValid

        public void setValid​(boolean valid)
        Description copied from interface: EditableValueHolder

        Set a flag indicating whether the local value of this component is valid (no conversion error has occurred).

        Specified by:
        setValid in interface EditableValueHolder
        Parameters:
        valid - The new valid flag
      • setRequired

        public void setRequired​(boolean required)

        Set the "required field" state for this component.

        Specified by:
        setRequired in interface EditableValueHolder
        Parameters:
        required - The new "required field" state
      • setImmediate

        public void setImmediate​(boolean immediate)
        Description copied from interface: EditableValueHolder

        Set the "immediate" state for this component. When set to true, the component's value will be converted and validated immediately in the Apply Request Values phase, and ValueChangeEvents will be delivered in that phase as well. The default value for this property must be false.

        Specified by:
        setImmediate in interface EditableValueHolder
        Parameters:
        immediate - The new "immediate" state
      • getValidator

        public MethodBinding getValidator​()
        Deprecated. getValidators() should be used instead.

        Return a MethodBinding pointing at a method that will be called during Process Validations phase of the request processing lifecycle, to validate the current value of this component.

        Specified by:
        getValidator in interface EditableValueHolder
      • processDecodes

        public void processDecodes​(FacesContext context)

        Specialized decode behavior on top of that provided by the superclass. In addition to the standard processDecodes behavior inherited from UIComponentBase, calls validate() if the the immediate property is true; if the component is invalid afterwards or a RuntimeException is thrown, calls FacesContext.renderResponse().

        Overrides:
        processDecodes in class UIComponentBase
        Parameters:
        context - FacesContext for the request we are processing
        Throws:
        java.lang.NullPointerException - if context is null
      • decode

        public void decode​(FacesContext context)
        Description copied from class: UIComponent

        Decode any new state of this UIComponent from the request contained in the specified FacesContext, and store this state as needed.

        During decoding, events may be enqueued for later processing (by event listeners who have registered an interest), by calling queueEvent().

        Overrides:
        decode in class UIComponentBase
        Parameters:
        context - FacesContext for the request we are processing
        Throws:
        java.lang.NullPointerException - if context is null
      • updateModel

        public void updateModel​(FacesContext context)

        Perform the following algorithm to update the model data associated with this UIInput, if any, as appropriate.

        Parameters:
        context - FacesContext for the request we are processing
        Throws:
        java.lang.NullPointerException - if context is null
      • validate

        public void validate​(FacesContext context)

        Perform the following algorithm to validate the local value of this UIInput.

        Application components implementing UIInput that wish to perform validation with logic embedded in the component should perform their own correctness checks, and then call the super.validate() method to perform the standard processing described above.

        Parameters:
        context - The FacesContext for the current request
        Throws:
        java.lang.NullPointerException - if context is null
      • getConvertedValue

        protected java.lang.Object getConvertedValue​(FacesContext context,
                                                     java.lang.Object newSubmittedValue)
                                              throws ConverterException

        Convert the submitted value into a "local value" of the appropriate data type, if necessary. Employ the following algorithm to do so:

        • If a Renderer is present, call getConvertedValue() to convert the submitted value.
        • If no Renderer is present, and the submitted value is a String, locate a Converter as follows:
          • If getConverter() returns a non-null Converter, use that instance.
          • Otherwise, if a value binding for value exists, call getType() on it.
            • If this call returns null, assume the output type is String and perform no conversion.
            • Otherwise, call Application.createConverter(Class) to locate any registered Converter capable of converting data values of the specified type.
        • If a Converter instance was located, call its getAsObject() method to perform the conversion. If conversion fails, the Converter will have thrown a ConverterException which is declared as a checked exception on this method, and thus must be handled by the caller.
        • Otherwise, use the submitted value without any conversion
      • This method can be overridden by subclasses for more specific behavior.

Throws:
ConverterException