Class ViewParam
- java.lang.Object
-
- jakarta.faces.component.UIComponent
-
- jakarta.faces.component.UIComponentBase
-
- jakarta.faces.component.UIOutput
-
- jakarta.faces.component.UIInput
-
- jakarta.faces.component.UIViewParameter
-
- org.omnifaces.component.input.ViewParam
-
- All Implemented Interfaces:
EditableValueHolder
,PartialStateHolder
,StateHolder
,TransientStateHolder
,ValueHolder
,ComponentSystemEventListener
,FacesListener
,SystemEventListenerHolder
,EventListener
- Direct Known Subclasses:
ComponentIdParam
public class ViewParam extends UIViewParameter
The
<o:viewParam>
is a component that extends the standard<f:viewParam>
and provides a stateless mode of operation and fixes the issue wherein null model values are converted to empty string parameters in query string (e.g. whenincludeViewParams=true
) and the (bean) validation never being triggered when the parameter is completely absent in query string, causing e.g.@NotNull
to fail.Stateless mode to avoid unnecessary conversion, validation and model updating on postbacks
The standard
UIViewParameter
implementation calls the model setter again after postback. This is not always desired when being bound to a view scoped bean and can lead to performance problems when combined with an expensive converter. To solve this, this component by default stores the submitted value as a component property instead of in the model (and thus in the view state in case the binding is to a view scoped bean).The standard
UIViewParameter
implementation calls the converter and validators again on postbacks. This is not always desired when you have e.g. arequired="true"
, but the parameter is not retained on form submit. You would need to retain it on every single command link/button by<f:param>
. To solve this, this component doesn't call the converter and validators again on postbacks.Using name as default for label
The
<o:viewParam>
also provides a default for thelabel
atrribute. When thelabel
attribute is omitted, thename
attribute will be used as label.Avoid unnecessary empty parameter in query string
The standard
UIViewParameter
implementation calls the converter regardless of whether the evaluated model value isnull
or not. As converters by specification return an empty string in case ofnull
value, this is being added to the query string as an empty parameter when e.g.includeViewParams=true
is used. This is not desired. The workaround was added in OmniFaces 1.8.Support bean validation and triggering validate events on null value
The standard
UIViewParameter
implementation uses in JSF 2.0-2.2 an internal "is required" check when the submitted value isnull
, hereby completely bypassing the standardUIInput
validation, including any bean validation annotations and even thePreValidateEvent
andPostValidateEvent
events. This is not desired. The workaround was added in OmniFaces 2.0. In JSF 2.3, this has been fixed and has only effect whenjakarta.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL
context param is set totrue
.Default value when no parameter is set
The
<o:viewParam>
also supports providing a default value via thedefault
attribute. When the parameter is not available, then the value specified indefault
attribute will be set in the model instead. The support was added in OmniFaces 2.2.Usage
You can use it the same way as
<f:viewParam>
, you only need to changef:
too:
.<o:viewParam name="foo" value="#{bean.foo}" />
- Author:
- Arjan Tijms, Bauke Scholtz
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jakarta.faces.component.UIViewParameter
UIViewParameter.Reference
-
-
Field Summary
Fields Modifier and Type Field Description static String
COMPONENT_TYPE
The component type, which is "org.omnifaces.component.input.ViewParam".-
Fields inherited from class jakarta.faces.component.UIViewParameter
COMPONENT_FAMILY
-
Fields 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_NAME
-
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 Constructor Description ViewParam()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,Object>
getAttributes()
String
getDefault()
Returns the default value in case the actual request parameter isnull
or empty.String
getStringValueFromModel(FacesContext context)
When there's a value expression and the evaluated model value isnull
, then just returnnull
instead of delegating to default implementation which would return an empty string when a converter is attached.String
getSubmittedValue()
boolean
isRequired()
void
processDecodes(FacesContext context)
void
processValidators(FacesContext context)
void
setDefault(String defaultValue)
Sets the default value in case the actual request parameter isnull
or empty.void
setSubmittedValue(Object submittedValue)
-
Methods inherited from class jakarta.faces.component.UIViewParameter
decode, encodeAll, getConvertedValue, getFamily, getName, getStringValue, isImmediate, setName, updateModel
-
Methods inherited from class jakarta.faces.component.UIInput
addValidator, addValueChangeListener, clearInitialState, compareValues, getConverterMessage, getRequiredMessage, getValidator, getValidatorMessage, getValidators, getValue, getValueChangeListener, getValueChangeListeners, isEmpty, isLocalValueSet, isValid, markInitialState, processUpdates, removeValidator, removeValueChangeListener, resetValue, restoreState, saveState, setConverterMessage, setImmediate, setLocalValueSet, setRequired, setRequiredMessage, setValid, setValidator, setValidatorMessage, setValue, setValueChangeListener, validate, validateValue
-
Methods inherited from class jakarta.faces.component.UIOutput
getConverter, getLocalValue, setConverter
-
Methods inherited from class jakarta.faces.component.UIComponentBase
addClientBehavior, addFacesListener, broadcast, encodeBegin, encodeChildren, encodeEnd, findComponent, 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, unsubscribeFromEvent
-
Methods inherited from class jakarta.faces.component.UIComponent
getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, visitTree
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jakarta.faces.component.ValueHolder
getConverter, getLocalValue, setConverter
-
-
-
-
Field Detail
-
COMPONENT_TYPE
public static final String COMPONENT_TYPE
The component type, which is "org.omnifaces.component.input.ViewParam".- See Also:
- Constant Field Values
-
-
Method Detail
-
processDecodes
public void processDecodes(FacesContext context)
- Overrides:
processDecodes
in classUIInput
-
processValidators
public void processValidators(FacesContext context)
- Overrides:
processValidators
in classUIViewParameter
-
getAttributes
public Map<String,Object> getAttributes()
- Overrides:
getAttributes
in classUIComponentBase
-
getStringValueFromModel
public String getStringValueFromModel(FacesContext context)
When there's a value expression and the evaluated model value isnull
, then just returnnull
instead of delegating to default implementation which would return an empty string when a converter is attached.- Overrides:
getStringValueFromModel
in classUIViewParameter
- Since:
- 1.8
-
getSubmittedValue
public String getSubmittedValue()
- Specified by:
getSubmittedValue
in interfaceEditableValueHolder
- Overrides:
getSubmittedValue
in classUIViewParameter
-
setSubmittedValue
public void setSubmittedValue(Object submittedValue)
- Specified by:
setSubmittedValue
in interfaceEditableValueHolder
- Overrides:
setSubmittedValue
in classUIViewParameter
-
getDefault
public String getDefault()
Returns the default value in case the actual request parameter isnull
or empty.- Returns:
- The default value in case the actual request parameter is
null
or empty. - Since:
- 2.2
-
setDefault
public void setDefault(String defaultValue)
Sets the default value in case the actual request parameter isnull
or empty.- Parameters:
defaultValue
- The default value in case the actual request parameter isnull
or empty.- Since:
- 2.2
-
isRequired
public boolean isRequired()
- Specified by:
isRequired
in interfaceEditableValueHolder
- Overrides:
isRequired
in classUIInput
-
-