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. when includeViewParams=true) and the (bean) validation never being
triggered when the parameter is completely absent in query string, causing e.g. @NotNull to fail.
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. a required="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.
The <o:viewParam> also provides a default for the label atrribute. When the
label attribute is omitted, the name attribute will be used as label.
The standard UIViewParameter implementation calls the converter regardless of whether the evaluated model
value is null or not. As converters by specification return an empty string in case of null
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.
The standard UIViewParameter implementation uses in JSF 2.0-2.2 an internal "is required" check when the
submitted value is null, hereby completely bypassing the standard UIInput validation, including
any bean validation annotations and even the PreValidateEvent and PostValidateEvent 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 when
javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL context param is set to true.
The <o:viewParam> also supports providing a default value via the new default
attribute. When the parameter is not available, then the value specified in default attribute will be
set in the model instead. The support was added in OmniFaces 2.2.
You can use it the same way as <f:viewParam>, you only need to change f: to
o:.
<o:viewParam name="foo" value="#{bean.foo}" />
UIViewParameter.Reference| Modifier and Type | Field and Description |
|---|---|
static String |
COMPONENT_TYPE |
COMPONENT_FAMILYALWAYS_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_NAMEATTRS_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 and Description |
|---|
ViewParam() |
| Modifier and Type | Method and Description |
|---|---|
Map<String,Object> |
getAttributes() |
String |
getDefault()
Returns the default value in case the actual request parameter is
null or empty. |
String |
getStringValueFromModel(FacesContext context)
When there's a value expression and the evaluated model value is
null, then just return
null 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 is
null or empty. |
void |
setSubmittedValue(Object submittedValue) |
decode, encodeAll, getConvertedValue, getFamily, getName, getStringValue, isImmediate, setName, updateModeladdValidator, 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, validateValuegetConverter, getLocalValue, setConverteraddClientBehavior, 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, unsubscribeFromEventgetClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, visitTreeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetConverter, getLocalValue, setConverterpublic static final String COMPONENT_TYPE
public void processDecodes(FacesContext context)
processDecodes in class UIInputpublic void processValidators(FacesContext context)
processValidators in class UIViewParameterpublic Map<String,Object> getAttributes()
getAttributes in class UIComponentBasepublic String getStringValueFromModel(FacesContext context)
null, then just return
null instead of delegating to default implementation which would return an empty string when a
converter is attached.getStringValueFromModel in class UIViewParameterpublic String getSubmittedValue()
getSubmittedValue in interface EditableValueHoldergetSubmittedValue in class UIViewParameterpublic void setSubmittedValue(Object submittedValue)
setSubmittedValue in interface EditableValueHoldersetSubmittedValue in class UIViewParameterpublic String getDefault()
null or empty.null or empty.public void setDefault(String defaultValue)
null or empty.defaultValue - The default value in case the actual request parameter is null or empty.public boolean isRequired()
isRequired in interface EditableValueHolderisRequired in class UIInputCopyright © 2012–2019 OmniFaces. All rights reserved.