- All Implemented Interfaces:
EditableValueHolder,PartialStateHolder,StateHolder,TransientStateHolder,ValueHolder,ComponentSystemEventListener,FacesListener,SystemEventListenerHolder,EventListener
The <o:inputHidden> is a component that extends the standard <h:inputHidden>
and changes the behavior to immediately convert, validate and update during apply request values phase, regardless of
any conversion/validation errors on other UIInput components within the same form. The standard
<h:inputHidden> follows the same lifecycle as other UIInput components which is in
the end unintuive as hidden input fields are usually under control of the developer.
Use case 1: Imagine a form with a <h:inputHidden> and a <h:inputText>. The
hidden input holds some prepopulated value of a request scoped bean which is intended to be passed through to the
request scoped bean instance of the next request. However, when conversion/validation fails on the text input, then
the hidden input won't update the bean property and then becomes empty. I.e. the original value gets permanently lost.
This can be bypassed by using ajax to update only specific fields, but this will fail when the update of the hidden
input is actually needed (e.g. because the value can possibly be adjusted in action/listener method).
Use case 2: Imagine a form with an UIInput or UICommand component whose
rendered attribute relies on a request scoped bean property which is retained for the next request
through a <h:inputHidden>. However, when Faces needs to decode the UIInput or
UICommand component during the postback, the rendered attribute has defaulted back to
false because the <h:inputHidden> hasn't yet updated the request scoped bean property
yet.
This behavior cannot be achieved by using immediate="true" on <h:inputHidden>. It
would only move the conversion/validation into the apply request values phase. The model still won't be updated on
time.
Also, the <h:inputHidden> didn't support the readonly attribute. This is however
useful when used in combination with a validator which should block the form submit. Since version 4.1, the
<o:inputHidden> supports this use case by simply grabbing and validating the model value during
the apply request values phase. The setter method associated with the model won't be invoked.
Usage
You can use it the same way as <h:inputHidden>, you only need to change h: into
o: to get the "immediate v2.0" behavior.
<h:form>
<o:inputHidden value="#{bean.hidden}" />
...
</h:form>
When using ajax, don't forget to make sure that the component is also covered by the execute attribute.
- Since:
- 3.7
- Author:
- Bauke Scholtz
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe component type, which is "org.omnifaces.component.input.InputHidden".Fields inherited from class jakarta.faces.component.html.HtmlInputHidden
COMPONENT_FAMILYFields inherited from class jakarta.faces.component.UIInput
ALWAYS_PERFORM_VALIDATION_WHEN_REQUIRED_IS_TRUE, CONVERSION_MESSAGE_ID, EMPTY_STRING_AS_NULL_PARAM_NAME, REQUIRED_MESSAGE_ID, UPDATE_MESSAGE_ID, VALIDATE_EMPTY_FIELDS_PARAM_NAMEFields inherited from class jakarta.faces.component.UIComponent
ATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, FACETS_KEY, VIEW_LOCATION_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddecode(FacesContext context) This override performs decode, validate and update at once.booleanReturns whether this component is readonly.voidprocessUpdates(FacesContext context) This override which does effectively nothing prevents Faces from performing update for second time.voidprocessValidators(FacesContext context) This override which does effectively nothing prevents Faces from performing validation for second time.voidsetReadonly(boolean readonly) Set whether this component is readonly.Methods inherited from class jakarta.faces.component.html.HtmlInputHidden
getFamilyMethods inherited from class jakarta.faces.component.UIInput
addValidator, addValueChangeListener, broadcast, clearInitialState, compareValues, getConvertedValue, getConverterMessage, getRequiredMessage, getSubmittedValue, getValidatorMessage, getValidators, getValue, getValueChangeListeners, isEmpty, isImmediate, isLocalValueSet, isRequired, isValid, markInitialState, processDecodes, removeValidator, removeValueChangeListener, resetValue, restoreState, saveState, setConverterMessage, setImmediate, setLocalValueSet, setRequired, setRequiredMessage, setSubmittedValue, setValid, setValidatorMessage, setValue, updateModel, validate, validateValueMethods inherited from class jakarta.faces.component.UIOutput
getConverter, getLocalValue, setConverterMethods inherited from class jakarta.faces.component.UIComponentBase
addClientBehavior, addFacesListener, encodeAll, encodeBegin, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getPassThroughAttributes, getRenderer, getRendererType, getRendersChildren, invokeOnComponent, isRendered, isTransient, processRestoreState, processSaveState, queueEvent, removeFacesListener, restoreAttachedState, saveAttachedState, setId, setParent, setRendered, setRendererType, setTransient, visitTreeMethods inherited from class jakarta.faces.component.UIComponent
getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getListenersForEventClass, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, subscribeToEvent, unsubscribeFromEventMethods 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 component type, which is "org.omnifaces.component.input.InputHidden".- See Also:
-
-
Constructor Details
-
InputHidden
public InputHidden()
-
-
Method Details
-
decode
This override performs decode, validate and update at once. -
processValidators
This override which does effectively nothing prevents Faces from performing validation for second time.- Overrides:
processValidatorsin classUIInput
-
processUpdates
This override which does effectively nothing prevents Faces from performing update for second time.- Overrides:
processUpdatesin classUIInput
-
isReadonly
public boolean isReadonly()Returns whether this component is readonly. Defaults tofalse. Note that even when this component is readonly, all associated validators will be invoked based on the model value, not on the submitted value. Also the setter won't be invoked.- Returns:
- Whether this component is readonly.
- Since:
- 4.1
-
setReadonly
public void setReadonly(boolean readonly) Set whether this component is readonly.- Parameters:
readonly- Whether this component is readonly.- Since:
- 4.1
-