Class UIInput
- All Implemented Interfaces:
EditableValueHolder,PartialStateHolder,StateHolder,TransientStateHolder,ValueHolder,ComponentSystemEventListener,FacesListener,SystemEventListenerHolder,EventListener
- Direct Known Subclasses:
HtmlInputFile,HtmlInputHidden,HtmlInputSecret,HtmlInputText,HtmlInputTextarea,UISelectBoolean,UISelectMany,UISelectOne,UIViewParameter
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringIf this param is set, and calling toLowerCase().equals("true") on a String representation of its value returns true, validation must be performed, even when there is no corresponding value for this component in the incoming request.static final StringThe standard component family for this component.static final StringThe standard component type for this component.static final StringThe message identifier of theFacesMessageto be created if a conversion error occurs, and neither the page author nor theConverterExceptionprovides a message.static final StringThe name of a context parameter that indicates how empty strings need to be interpreted.static final StringThe message identifier of theFacesMessageto be created if a required check fails.static final StringThe message identifier of theFacesMessageto be created if a model update error occurs, and the thrown exception has no message.static final StringThe name of a context parameter that indicates how empty values should be handled with respect to validation.Fields inherited from class jakarta.faces.component.UIComponent
ATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, CURRENT_COMPONENT, CURRENT_COMPOSITE_COMPONENT, FACETS_KEY, HONOR_CURRENT_COMPONENT_ATTRIBUTES_PARAM_NAME, VIEW_LOCATION_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddValidator(Validator validator) voidaddValueChangeListener(ValueChangeListener listener) Add a newValueChangeListenerto the set of listeners interested in being notified whenValueChangeEvents occur.voidFor each of the attached objects on this instance that implementPartialStateHolder, callPartialStateHolder.clearInitialState()on the attached object.protected booleancompareValues(Object previous, Object value) Returntrueif the new value is different from the previous value.voiddecode(FacesContext context) Decode any new state of thisUIComponentfrom the request contained in the specifiedFacesContext, and store this state as needed.protected ObjectgetConvertedValue(FacesContext context, Object newSubmittedValue) Convert the submitted value into a "local value" of the appropriate data type, if necessary.If there has been a call tosetConverterMessage(java.lang.String)on this instance, return the message.Return the identifier of the component family to which this component belongs.If there has been a call tosetRequiredMessage(java.lang.String)on this instance, return the message.Return the submittedValue value of thisUIInputcomponent.Deprecated.If there has been a call tosetValidatorMessage(java.lang.String)on this instance, return the message.getValue()If there is a local value, return it, otherwise return the result of callingsuper.getVaue().IfEditableValueHolder.setValueChangeListener(jakarta.faces.el.MethodBinding)was not previously called for this instance, this method must returnnull.Return the set of registeredValueChangeListeners for thisUIInputinstance.static booleanIs the value denoting an empty value.booleanReturn the "immediate" state for this component.booleanReturn the "local value set" state for this component.booleanReturn the "required field" state for this component.booleanisValid()Return a flag indicating whether the local value of this component is valid (no conversion error has occurred).voidIn addition to the actions taken inUIOutputwhenPartialStateHolder.markInitialState()is called, check if any of the installedValidators are PartialStateHolders and if so, callPartialStateHolder.markInitialState()as appropriate.voidprocessDecodes(FacesContext context) Specialized decode behavior on top of that provided by the superclass.voidprocessUpdates(FacesContext context) In addition to the standardprocessUpdatesbehavior inherited fromUIComponentBase, callsupdateModel().voidprocessValidators(FacesContext context) In addition to the standardprocessValidatorsbehavior inherited fromUIComponentBase, callsvalidate()if theimmediateproperty is false (which is the default); if the component is invalid afterwards, callsFacesContext.renderResponse().voidremoveValidator(Validator validator) voidremoveValueChangeListener(ValueChangeListener listener) Remove an existingValueChangeListener(if any) from the set of listeners interested in being notified whenValueChangeEvents occur.voidConvenience method to reset this component's value to the un-initialized state.voidrestoreState(FacesContext context, Object state) Perform any processing required to restore the state from the entries in the state Object.saveState(FacesContext context) Gets the state of the instance as aSerializableObject.voidsetConverterMessage(String message) Override anyValueExpressionset for the "converterMessage" with the literal argument provided to this method.voidsetImmediate(boolean immediate) Set the "immediate" state for this component.voidsetLocalValueSet(boolean localValueSet) Sets the "local value set" state for this component.voidsetRequired(boolean required) Set the "required field" state for this component.voidsetRequiredMessage(String message) Override anyValueExpressionset for the "requiredMessage" with the literal argument provided to this method.voidsetSubmittedValue(Object submittedValue) Set the submittedValue value of thisUIInputcomponent.voidsetValid(boolean valid) Set a flag indicating whether the local value of this component is valid (no conversion error has occurred).voidsetValidator(MethodBinding validatorBinding) Deprecated.UseaddValidator(jakarta.faces.validator.Validator)instead, obtaining the argumentValidatorby creating an instance ofMethodExpressionValidator.voidsetValidatorMessage(String message) Override anyValueExpressionset for the "validatorMessage" with the literal argument provided to this method.voidSet the value of thisUIComponent(if any).voidsetValueChangeListener(MethodBinding valueChangeListener) Deprecated.UseaddValueChangeListener(jakarta.faces.event.ValueChangeListener)instead, obtaining the argumentValueChangeListenerby creating an instance ofMethodExpressionValueChangeListener.voidupdateModel(FacesContext context) Perform the following algorithm to update the model data associated with thisUIInput, if any, as appropriate.voidvalidate(FacesContext context) Perform the following algorithm to validate the local value of thisUIInput.protected voidvalidateValue(FacesContext context, Object newValue) Set the "valid" property according to the below algorithm.Methods inherited from class jakarta.faces.component.UIOutput
getConverter, getLocalValue, setConverterMethods inherited from class jakarta.faces.component.UIComponentBase
addClientBehavior, addFacesListener, broadcast, encodeBegin, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getRendersChildren, getValueBinding, invokeOnComponent, isRendered, isTransient, processRestoreState, processSaveState, queueEvent, removeFacesListener, restoreAttachedState, saveAttachedState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding, subscribeToEvent, unsubscribeFromEventMethods inherited from class jakarta.faces.component.UIComponent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, visitTreeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.faces.component.ValueHolder
getConverter, getLocalValue, setConverter
-
Field Details
-
COMPONENT_TYPE
The standard component type for this component.
- See Also:
-
COMPONENT_FAMILY
The standard component family for this component.
- See Also:
-
CONVERSION_MESSAGE_ID
The message identifier of the
FacesMessageto be created if a conversion error occurs, and neither the page author nor theConverterExceptionprovides a message.- See Also:
-
REQUIRED_MESSAGE_ID
The message identifier of the
FacesMessageto be created if a required check fails.- See Also:
-
UPDATE_MESSAGE_ID
The message identifier of the
FacesMessageto be created if a model update error occurs, and the thrown exception has no message.- See Also:
-
VALIDATE_EMPTY_FIELDS_PARAM_NAME
The name of a context parameter that indicates how empty values should be handled with respect to validation. See
validateValue(jakarta.faces.context.FacesContext, java.lang.Object)for the allowable values and specification of how they should be interpreted.- See Also:
-
EMPTY_STRING_AS_NULL_PARAM_NAME
The name of a context parameter that indicates how empty strings need to be interpreted.
- See Also:
-
ALWAYS_PERFORM_VALIDATION_WHEN_REQUIRED_IS_TRUE
If this param is set, and calling toLowerCase().equals("true") on a String representation of its value returns true, validation must be performed, even when there is no corresponding value for this component in the incoming request. See
validate(jakarta.faces.context.FacesContext).- See Also:
-
-
Constructor Details
-
UIInput
public UIInput()Create a new
UIInputinstance with default property values.
-
-
Method Details
-
getFamily
Description copied from class:UIComponentReturn the identifier of the component family to which this component belongs. This identifier, in conjunction with the value of the
rendererTypeproperty, may be used to select the appropriateRendererfor this component instance. Note this method should NOT returnnull -
getSubmittedValue
Return the submittedValue value of this
UIInputcomponent. This method should only be used by thedecode()andvalidate()method of this component, or its correspondingRenderer.- Specified by:
getSubmittedValuein interfaceEditableValueHolder- Returns:
- the submitted value.
-
setSubmittedValue
Set the submittedValue value of this
UIInputcomponent. This method should only be used by thedecode()andvalidate()method of this component, or its correspondingRenderer.- Specified by:
setSubmittedValuein interfaceEditableValueHolder- Parameters:
submittedValue- The new submitted value
-
getValue
If there is a local value, return it, otherwise return the result of calling
super.getVaue().- Specified by:
getValuein interfaceValueHolder- Overrides:
getValuein classUIOutput- Returns:
- the value.
- Since:
- 2.2
-
setValue
Description copied from interface:ValueHolderSet the value of this
UIComponent(if any).- Specified by:
setValuein interfaceValueHolder- Overrides:
setValuein classUIOutput- Parameters:
value- The new local value
-
resetValue
public void resetValue()Convenience method to reset this component's value to the un-initialized state. This method does the following:
Call
UIOutput.setValue(java.lang.Object).Call
setSubmittedValue(java.lang.Object)passingnull.Clear state for property
localValueSet.Clear state for property
valid.Upon return from this call if the instance had a
ValueBindingassociated with it for the "value" property, this binding is evaluated whenUIOutput.getValue()is called. Otherwise,nullis returned fromgetValue().- Specified by:
resetValuein interfaceEditableValueHolder- Overrides:
resetValuein classUIOutput
-
isLocalValueSet
public boolean isLocalValueSet()Return the "local value set" state for this component. Calls tosetValue()automatically reset this property totrue.- Specified by:
isLocalValueSetin interfaceEditableValueHolder- Returns:
trueif the local value is set,falseotherwise.
-
setLocalValueSet
public void setLocalValueSet(boolean localValueSet) Sets the "local value set" state for this component.- Specified by:
setLocalValueSetin interfaceEditableValueHolder- Parameters:
localValueSet- the "local value set" boolean.
-
isRequired
public boolean isRequired()Return the "required field" state for this component.
- Specified by:
isRequiredin interfaceEditableValueHolder- Returns:
trueif required,falseotherwise.
-
getRequiredMessage
If there has been a call to
setRequiredMessage(java.lang.String)on this instance, return the message. Otherwise, callUIComponent.getValueExpression(java.lang.String)passing the key "requiredMessage", get the result of the expression, and return it. AnyELExceptions thrown during the call togetValue()must be wrapped in aFacesExceptionand rethrown.- Returns:
- the required message.
-
setRequiredMessage
Override any
ValueExpressionset for the "requiredMessage" with the literal argument provided to this method. Subsequent calls togetRequiredMessage()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.
-
getConverterMessage
If there has been a call to
setConverterMessage(java.lang.String)on this instance, return the message. Otherwise, callUIComponent.getValueExpression(java.lang.String)passing the key "converterMessage", get the result of the expression, and return it. AnyELExceptions thrown during the call togetValue()must be wrapped in aFacesExceptionand rethrown.- Returns:
- the converter message.
-
setConverterMessage
Override any
ValueExpressionset for the "converterMessage" with the literal argument provided to this method. Subsequent calls togetConverterMessage()will return this value;- Parameters:
message- the literal message value to be displayed in the event conversion fails.
-
getValidatorMessage
If there has been a call to
setValidatorMessage(java.lang.String)on this instance, return the message. Otherwise, callUIComponent.getValueExpression(java.lang.String)passing the key "validatorMessage", get the result of the expression, and return it. AnyELExceptions thrown during the call togetValue()must be wrapped in aFacesExceptionand rethrown.- Returns:
- the validator message.
-
setValidatorMessage
Override any
ValueExpressionset for the "validatorMessage" with the literal argument provided to this method. Subsequent calls togetValidatorMessage()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:EditableValueHolderReturn a flag indicating whether the local value of this component is valid (no conversion error has occurred).
- Specified by:
isValidin interfaceEditableValueHolder- Returns:
trueif valid,falseotherwise.
-
setValid
public void setValid(boolean valid) Description copied from interface:EditableValueHolderSet a flag indicating whether the local value of this component is valid (no conversion error has occurred).
- Specified by:
setValidin interfaceEditableValueHolder- Parameters:
valid- The new valid flag
-
setRequired
public void setRequired(boolean required) Set the "required field" state for this component.
- Specified by:
setRequiredin interfaceEditableValueHolder- Parameters:
required- The new "required field" state
-
isImmediate
public boolean isImmediate()Description copied from interface:EditableValueHolderReturn the "immediate" state for this component.
- Specified by:
isImmediatein interfaceEditableValueHolder- Returns:
trueif is immediate,falseotherwise.
-
setImmediate
public void setImmediate(boolean immediate) Description copied from interface:EditableValueHolderSet 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 befalse.- Specified by:
setImmediatein interfaceEditableValueHolder- Parameters:
immediate- The new "immediate" state
-
getValidator
Deprecated.getValidators()should be used instead.Return a
MethodBindingpointing 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:
getValidatorin interfaceEditableValueHolder- Returns:
- the validator as a method binding.
-
setValidator
Deprecated.UseaddValidator(jakarta.faces.validator.Validator)instead, obtaining the argumentValidatorby creating an instance ofMethodExpressionValidator.Set a
MethodBindingpointing at a method that will be called during Process Validations phase of the request processing lifecycle, to validate the current value of this component.Any method referenced by such an expression must be public, with a return type of
void, and accept parameters of typeFacesContext,UIComponent, andObject.- Specified by:
setValidatorin interfaceEditableValueHolder- Parameters:
validatorBinding- The newMethodBindinginstance
-
getValueChangeListener
Description copied from interface:EditableValueHolderIf
EditableValueHolder.setValueChangeListener(jakarta.faces.el.MethodBinding)was not previously called for this instance, this method must returnnull. If it was called, this method must return the exactMethodBindinginstance that was passed toEditableValueHolder.setValueChangeListener(jakarta.faces.el.MethodBinding).- Specified by:
getValueChangeListenerin interfaceEditableValueHolder- Returns:
- the value change listener.
-
setValueChangeListener
Deprecated.UseaddValueChangeListener(jakarta.faces.event.ValueChangeListener)instead, obtaining the argumentValueChangeListenerby creating an instance ofMethodExpressionValueChangeListener.Wrap the argument
valueChangeMethodin an implementation ofValueChangeListenerand store it in the internal data structure that backs theEditableValueHolder.getValueChangeListeners()method, taking care to over-write any instance that was stored by a previous call tosetValueChangeListener.This argument method will be called during the Process Validations or Apply Request Values phases (depending on the value of the
immediateproperty).Any method referenced by such an expression must be public, with a return type of
void, and accept a parameter of typeValueChangeEvent.- Specified by:
setValueChangeListenerin interfaceEditableValueHolder- Parameters:
valueChangeListener- the value change listener.
-
markInitialState
public void markInitialState()In addition to the actions taken in
UIOutputwhenPartialStateHolder.markInitialState()is called, check if any of the installedValidators are PartialStateHolders and if so, callPartialStateHolder.markInitialState()as appropriate.- Specified by:
markInitialStatein interfacePartialStateHolder- Overrides:
markInitialStatein classUIOutput
-
clearInitialState
public void clearInitialState()Description copied from class:UIComponentBaseFor each of the attached objects on this instance that implement
PartialStateHolder, callPartialStateHolder.clearInitialState()on the attached object.- Specified by:
clearInitialStatein interfacePartialStateHolder- Overrides:
clearInitialStatein classUIOutput
-
processDecodes
Specialized decode behavior on top of that provided by the superclass. In addition to the standard
processDecodesbehavior inherited fromUIComponentBase, callsvalidate()if the theimmediateproperty is true; if the component is invalid afterwards or aRuntimeExceptionis thrown, callsFacesContext.renderResponse().- Overrides:
processDecodesin classUIComponentBase- Parameters:
context-FacesContextfor the request we are processing- Throws:
NullPointerException- ifcontextisnull
-
processValidators
In addition to the standard
processValidatorsbehavior inherited fromUIComponentBase, callsvalidate()if theimmediateproperty is false (which is the default); if the component is invalid afterwards, callsFacesContext.renderResponse(). To ensure thePostValidateEventis published at the proper time, this component must be validated first, followed by the component's children and facets. If aRuntimeExceptionis thrown during validation processing, callsFacesContext.renderResponse()and re-throw the exception.- Overrides:
processValidatorsin classUIComponentBase- Parameters:
context-FacesContextfor the request we are processing- Throws:
NullPointerException- ifcontextisnull- See Also:
-
processUpdates
In addition to the standard
processUpdatesbehavior inherited fromUIComponentBase, callsupdateModel(). If the component is invalid afterwards, callsFacesContext.renderResponse(). If aRuntimeExceptionis thrown during update processing, callsFacesContext.renderResponse()and re-throw the exception.- Overrides:
processUpdatesin classUIComponentBase- Parameters:
context-FacesContextfor the request we are processing- Throws:
NullPointerException- ifcontextisnull
-
decode
Description copied from class:UIComponentDecode any new state of this
UIComponentfrom the request contained in the specifiedFacesContext, 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:
decodein classUIComponentBase- Parameters:
context-FacesContextfor the request we are processing- Throws:
NullPointerException- ifcontextisnull
-
updateModel
Perform the following algorithm to update the model data associated with this
UIInput, if any, as appropriate.- If the
validproperty of this component isfalse, take no further action. - If the
localValueSetproperty of this component isfalse, take no further action. - If no
ValueExpressionforvalueexists, take no further action. - Call
setValue()method of theValueExpressionto update the value that theValueExpressionpoints at. - If the
setValue()method returns successfully: - If the
setValue()method throws an Exception:- Enqueue an error message. Create a
FacesMessagewith the idUPDATE_MESSAGE_ID. Create aUpdateModelException, passing theFacesMessageand the caught exception to the constructor. Create anExceptionQueuedEventContext, passing theFacesContext, theUpdateModelException, this component instance, andPhaseId.UPDATE_MODEL_VALUESto its constructor. CallFacesContext.getExceptionHandler()and then callExceptionHandler.processEvent(jakarta.faces.event.SystemEvent), passing theExceptionQueuedEventContext. - Set the
validproperty of thisUIInputtofalse.
- Enqueue an error message. Create a
- Parameters:
context-FacesContextfor the request we are processing- Throws:
NullPointerException- ifcontextisnull
- If the
-
validate
Perform the following algorithm to validate the local value of this
UIInput.- Retrieve the submitted value with
getSubmittedValue(). If this returnsnull, and the value of theALWAYS_PERFORM_VALIDATION_WHEN_REQUIRED_IS_TRUEcontext-param is true (ignoring case), examine the value of the "required" property. If the value of "required" is true, continue as below. If the value of "required" is false or the required attribute is not set, exit without further processing. If the context-param is not set, or is set to false (ignoring case), exit without further processing. (This indicates that no value was submitted for this component.) - If the
jakarta.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULLcontext parameter value istrue(ignoring case), andgetSubmittedValue()returns a zero-lengthStringcall, passingsetSubmittedValue(java.lang.Object)nullas the argument and continue processing usingnullas the current submitted value. - Convert the submitted value into a "local value" of the appropriate data type by calling
getConvertedValue(jakarta.faces.context.FacesContext, java.lang.Object). - If conversion fails:
- Enqueue an appropriate error message by calling the
addMessage()method on theFacesContext. - Set the
validproperty on this component tofalse
- Enqueue an appropriate error message by calling the
- Validate the property by calling
validateValue(jakarta.faces.context.FacesContext, java.lang.Object). - If the
validproperty of this component is stilltrue, retrieve the previous value of the component (withgetValue()), store the new local value usingsetValue(), and reset the submitted value to null with a call tosetSubmittedValue(java.lang.Object)passingnullas the argument. If the local value is different from the previous value of this component, as determined by a call tocompareValues(java.lang.Object, java.lang.Object), fire aValueChangeEventto be broadcast to all interested listeners.
Application components implementing
UIInputthat wish to perform validation with logic embedded in the component should perform their own correctness checks, and then call thesuper.validate()method to perform the standard processing described above.- Parameters:
context- TheFacesContextfor the current request- Throws:
NullPointerException- ifcontextis null
- Retrieve the submitted value with
-
getConvertedValue
protected Object getConvertedValue(FacesContext context, 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
Rendereris present, callgetConvertedValue()to convert the submitted value. - If no
Rendereris present, and the submitted value is a String, locate aConverteras follows:- If
getConverter()returns a non-nullConverter, use that instance. - Otherwise, if a value binding for
valueexists, callgetType()on it.- If this call returns
null, assume the output type isStringand perform no conversion. - Otherwise, call
Application.createConverter(Class)to locate any registeredConvertercapable of converting data values of the specified type.
- If this call returns
- If
- If a
Converterinstance was located, call itsgetAsObject()method to perform the conversion. If conversion fails, theConverterwill have thrown aConverterExceptionwhich 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.
- Parameters:
context- the Faces context.newSubmittedValue- the new submitted value.- Returns:
- the converted value.
- Throws:
ConverterException
- If a
-
validateValue
Set the "valid" property according to the below algorithm.
-
If the
validproperty on this component is stilltrue, and therequiredproperty is alsotrue, ensure that the local value is not empty (where "empty" is defined asnullor a zero-length String). If the local value is empty:-
Enqueue an appropriate error message by calling the
addMessage()method on theFacesContextinstance for the current request. If thegetRequiredMessage()returns non-null, use the value as thesummaryanddetailin theFacesMessagethat is enqueued on theFacesContext, otherwise use the message for theREQUIRED_MESSAGE_ID. - Set the
validproperty on this component tofalse. -
If calling
ValidatorException.getFacesMessages()returns non-null, each message should be added to theFacesContext. Otherwise the single message returned fromValidatorException.getFacesMessage()should be added.
-
-
Otherwise, if the
validproperty on this component is stilltrue, 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
Mapfrom theExternalContextand inspect the value for the key given by the value of the symbolic constantVALIDATE_EMPTY_FIELDS_PARAM_NAME. If there is no value under that key, use the same key and look in the application map from theExternalContext. If the value isnullor 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 eachValidatorregistered for thisUIInput, followed by the method pointed at by thevalidatorBindingproperty (if any). If any of these validators or the method throws aValidatorException, catch the exception, add its message (if any) to theFacesContext, and set thevalidproperty of this component to false. -
- Parameters:
context- the Faces context.newValue- the new value.
-
-
compareValues
Return
trueif the new value is different from the previous value. First compare the two values by passing value to theequalsmethod on argument previous. If that method returnstrue, returntrue. If that method returnsfalse, and both arguments implementjava.lang.Comparable, compare the two values by passing value to thecompareTomethod on argument previous. Returntrueif this method returns0,falseotherwise.- Parameters:
previous- old value of this component (if any)value- new value of this component (if any)- Returns:
trueif the new value is different from the previous value,falseotherwise.
-
isEmpty
Is the value denoting an empty value.
If the value is null, return true. If the value is a String and it is the empty string, return true. If the value is an array and the array length is 0, return true. If the value is a List and the List is empty, return true. If the value is a Collection and the Collection is empty, return true. If the value is a Map and the Map is empty, return true. In all other cases, return false.
- Parameters:
value- the value to check.- Returns:
- true if it is, false otherwise.
-
addValidator
- Specified by:
addValidatorin interfaceEditableValueHolder- Parameters:
validator- TheValidatorto add- Throws:
NullPointerException- ifvalidatoris null
-
getValidators
Return the set of registered
Validators for thisUIInputinstance. If there are no registered validators, a zero-length array is returned.- Specified by:
getValidatorsin interfaceEditableValueHolder- Returns:
- the validators, or a zero-length array.
-
removeValidator
Remove a
Validatorinstance from the set associated with thisUIInput, if it was previously associated. Otherwise, do nothing.- Specified by:
removeValidatorin interfaceEditableValueHolder- Parameters:
validator- TheValidatorto remove
-
addValueChangeListener
Add a new
ValueChangeListenerto the set of listeners interested in being notified whenValueChangeEvents occur.- Specified by:
addValueChangeListenerin interfaceEditableValueHolder- Parameters:
listener- TheValueChangeListenerto be added- Throws:
NullPointerException- iflistenerisnull
-
getValueChangeListeners
Return the set of registered
ValueChangeListeners for thisUIInputinstance. If there are no registered listeners, a zero-length array is returned.- Specified by:
getValueChangeListenersin interfaceEditableValueHolder- Returns:
- the value change listeners, or a zero-length array.
-
removeValueChangeListener
Remove an existing
ValueChangeListener(if any) from the set of listeners interested in being notified whenValueChangeEvents occur.- Specified by:
removeValueChangeListenerin interfaceEditableValueHolder- Parameters:
listener- TheValueChangeListenerto be removed- Throws:
NullPointerException- iflistenerisnull
-
saveState
Description copied from interface:StateHolderGets the state of the instance as a
SerializableObject.If the class that implements this interface has references to instances that implement StateHolder (such as a
UIComponentwith event handlers, validators, etc.) this method must call theStateHolder.saveState(jakarta.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 theStateManagerThis method must not alter the state of the implementing object. In other words, after executing this code:
Object state = component.saveState(facesContext);componentshould be the same as before executing it.The return from this method must be
Serializable- Specified by:
saveStatein interfaceStateHolder- Overrides:
saveStatein classUIOutput- Parameters:
context- the Faces context.- Returns:
- the saved state.
-
restoreState
Description copied from interface:StateHolderPerform any processing required to restore the state from the entries in the state Object.
If the class that implements this interface has references to instances that also implement StateHolder (such as a
UIComponentwith event handlers, validators, etc.) this method must call theStateHolder.restoreState(jakarta.faces.context.FacesContext, java.lang.Object)method on all those instances as well.If the
stateargument isnull, take no action and return.- Specified by:
restoreStatein interfaceStateHolder- Overrides:
restoreStatein classUIOutput- Parameters:
context- the Faces context.state- the state.
-
getValidators()should be used instead.