public abstract class ValidateMultipleFields extends ValidatorFamily
validateValues(FacesContext, List, List)
method to perform the actual validation.
This validator must be placed inside the same UIForm
as the UIInput
components in question.
The UIInput
components must be referenced by a space separated collection of their client IDs in the
components
attribute. This validator can be placed anywhere in the form, but keep in mind that the
components will be validated in the order as they appear in the form. So if this validator is been placed before all
of the components, then it will be executed before any of the component's own validators. If this validator fails,
then the component's own validators will not be fired. If this validator is been placed after all of the components,
then it will be executed after any of the component's own validators. If any of them fails, then this validator
will not be exeucted. It is not recommended to put this validator somewhere in between the referenced components as
the resulting behaviour may be confusing. Put this validator either before or after all of the components, depending
on how you would like to prioritize the validation.
<o:validateMultipleFields id="myId" components="foo bar baz" /> <h:message for="myId" /> <h:inputText id="foo" /> <h:inputText id="bar" /> <h:inputText id="baz" />
In an invalidating case, all of the referenced components will be marked invalid and a faces message will be added
on the client ID of this validator component. The default message can be changed by the message
attribute. Any "{0}" placeholder in the message will be substituted with a comma separated string of labels of the
referenced input components.
<o:validateMultipleFields components="foo bar baz" message="{0} are wrong!" />
The faces message can also be shown for all of the referenced components using showMessageFor="@all"
.
<o:validateMultipleFields components="foo bar baz" message="This is wrong!" showMessageFor="@all" /> <h:inputText id="foo" /> <h:message for="foo" /> <h:inputText id="bar" /> <h:message for="bar" /> <h:inputText id="baz" /> <h:message for="baz" />
The showMessageFor
attribute defaults to @this
. Other values than @this
or
@all
are not allowed.
The validator can be disabled by the disabled
attribute. It accepts a request based EL expression.
<o:validateMultipleFields components="foo bar baz" disabled="#{param.validationDisabled}" />
There is a read-only validationFailed
attribute which can be used to determine if the validation by
this component has failed.
<o:validateMultipleFields id="myId" binding="#{myId}" components="foo bar baz" /> <h:panelGroup rendered="#{myId.validationFailed}"> Validation has failed! <h:message for="myId" /> </h:panelGroup>
TODO: support for immediate="true".
COMPONENT_FAMILY
BEANINFO_KEY, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, CURRENT_COMPONENT, CURRENT_COMPOSITE_COMPONENT, FACETS_KEY, VIEW_LOCATION_KEY
Constructor and Description |
---|
ValidateMultipleFields(String defaultMessage)
The default constructor sets the default message and sets the renderer type to
null . |
Modifier and Type | Method and Description |
---|---|
String |
getComponents()
Returns the client identifiers of components which are to be validated.
|
String |
getMessage()
Returns the validation message to be shown.
|
String |
getShowMessageFor()
Returns the client identifier to show the validation message for.
|
Boolean |
isDisabled()
Returns whether the validation should be disabled or not.
|
boolean |
isValidationFailed()
Returns whether the validation has failed or not.
|
void |
setComponents(String components)
Sets the client identifiers of components which are to be validated.
|
void |
setDisabled(Boolean disabled)
Sets whether the validation should be disabled or not.
|
void |
setMessage(String message)
Sets the validation message to be shown.
|
void |
setShowMessageFor(String showMessageFor)
Sets the client identifier to show the validation message for.
|
encodeChildren, getFamily, getRendersChildren, processDecodes, processUpdates, processValidators
addClientBehavior, broadcast, clearInitialState, decode, encodeBegin, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getRendererType, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processRestoreState, processSaveState, queueEvent, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getListenersForEventClass, getNamingContainer, getResourceBundleMap, getValueExpression, initialStateMarked, isCompositeComponent, isInView, popComponentFromEL, processEvent, pushComponentToEL, setInView, setValueExpression, subscribeToEvent, unsubscribeFromEvent, visitTree
public ValidateMultipleFields(String defaultMessage)
null
.public String getComponents()
public void setComponents(String components)
components
- The client identifiers of components which are to be validated.public String getMessage()
public void setMessage(String message)
message
- The validation message to be shown.public String getShowMessageFor()
public void setShowMessageFor(String showMessageFor)
showMessageFor
- The client identifier to show the validation message for.public Boolean isDisabled()
public void setDisabled(Boolean disabled)
disabled
- Whether the validation should be disabled or not.public boolean isValidationFailed()