- java.lang.Object
- 
- jakarta.faces.component.UIComponent
- 
- jakarta.faces.component.UIComponentBase
- 
- org.omnifaces.component.validator.ValidatorFamily
- 
- org.omnifaces.component.validator.ValidateMultipleFields
 
 
 
 
- 
- All Implemented Interfaces:
- PartialStateHolder,- StateHolder,- TransientStateHolder,- ComponentSystemEventListener,- FacesListener,- SystemEventListenerHolder,- EventListener,- MultiFieldValidator
 - Direct Known Subclasses:
- ValidateAll,- ValidateAllOrNone,- ValidateEqual,- ValidateMultiple,- ValidateOne,- ValidateOneOrMore,- ValidateOneOrNone,- ValidateOrder,- ValidateUnique
 
 public abstract class ValidateMultipleFields extends ValidatorFamily implements MultiFieldValidator Base class which is to be shared between all multi field validators. The implementors have to call the super constructor with the default message. The implementors have to override theMultiFieldValidator.validateValues(FacesContext, List, List)method to perform the actual validation.
 General usage of all multiple field validatorsThis validator must be placed inside the same UIFormas theUIInputcomponents in question. TheUIInputcomponents must be referenced by a space separated collection of their client IDs in thecomponentsattribute. Since version 3.13 you can also specify a single client ID of a common parent. This validator can be placed anywhere in the form, but keep in mind that the components will be converted and 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 converters and validators. If this validator fails, then the component's own converters and 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 converters and 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, for example because only the values of preceding components are converted and the values of following components are not converted. 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" /> When a target component is disabled="true",readonly="true"orrendered="false", then thevaluesargument ofMultiFieldValidator.validateValues(FacesContext, List, List), will instead contain the initial model value. This is quite useful when you need to validate against an existing model.By default, 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 messageattribute. 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!" />You can also change the default message in the message bundle file as identified by <application><message-bundle>infaces-config.xml. The message key is just the component type as identified byCOMPONENT_TYPEconstant of the validator component. For example,ValidateAllhas aValidateAll.COMPONENT_TYPEvalue oforg.omnifaces.component.validator.ValidateAll. Use exactly this value as message bundle key:org.omnifaces.component.validator.ValidateAll = {0} are wrong!You can use invalidateAll="false"to mark only those components which are actually invalid as invalid. In case of for example "input all" or "input all or none" validation, that would be only the fields which are left empty.<o:validateMultipleFields components="foo bar baz" message="{0} are wrong!" invalidateAll="false" />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 faces message can also be shown for only the invalidated components using showMessageFor="@invalid".<o:validateMultipleFields components="foo bar baz" message="This is wrong!" showMessageFor="@invalid" /> The faces message can also be shown as global message using showMessageFor="@global".<o:validateMultipleFields components="foo bar baz" message="This is wrong!" showMessageFor="@global" /> The faces message can also be shown for specific components referenced by a space separated collection of their client IDs in showMessageForattribute.<o:validateMultipleFields components="foo bar baz" message="This is wrong!" showMessageFor="foo baz" /> The showMessageForattribute defaults to@this.The validator can be disabled by the disabledattribute. It accepts a request based EL expression.<o:validateMultipleFields components="foo bar baz" disabled="#{param.validationDisabled}" />There is a read-only validationFailedattribute 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". - Author:
- Bauke Scholtz
 
- 
- 
Field Summary- 
Fields inherited from class org.omnifaces.component.validator.ValidatorFamilyCOMPONENT_FAMILY
 - 
Fields inherited from class jakarta.faces.component.UIComponentATTRS_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 SummaryConstructors Modifier Constructor Description protectedValidateMultipleFields()The default constructor sets the default message and sets the renderer type tonull.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected List<UIInput>collectComponents()Collect the input components.protected List<Object>collectValues(List<UIInput> inputs)Collect the values of the given input components.StringgetComponents()Returns the client identifiers of components which are to be validated.StringgetMessage()Returns the validation message to be shown.StringgetShowMessageFor()Returns the client identifiers to show the validation message for.booleanisDisabled()Returns whether the validation should be disabled or not.booleanisInvalidateAll()Returns whether to invalidate all fields or only those which are actually invalid as pershouldInvalidateInput(FacesContext, UIInput, Object)booleanisValidationFailed()Returns whether the validation has failed or not.voidsetComponents(String components)Sets the client identifiers of components which are to be validated.voidsetDisabled(boolean disabled)Sets whether the validation should be disabled or not.voidsetInvalidateAll(boolean invalidateAll)Sets whether to invalidate all fields or only those which are actually invalid as pershouldInvalidateInput(FacesContext, UIInput, Object)voidsetMessage(String message)Sets the validation message to be shown.voidsetShowMessageFor(String showMessageFor)Sets the client identifiers to show the validation message for.protected booleanshouldInvalidateInput(FacesContext context, UIInput input, Object value)Returns whether in in an invalidating case the given input component should be marked invalid.protected voidshowMessage(FacesContext context, List<UIInput> inputs)Show the message at the desired place(s) depending on the value of theshowMessageForattribute.protected voidvalidateComponents(FacesContext context)If the validation is not disabled, collect the components, if it is not empty, then collect their values and delegate toMultiFieldValidator.validateValues(FacesContext, List, List).protected voidvalidateHierarchy()Validate our component hierarchy.- 
Methods inherited from class org.omnifaces.component.validator.ValidatorFamilyencodeChildren, getFamily, getRendersChildren, processDecodes, processUpdates, processValidators
 - 
Methods inherited from class jakarta.faces.component.UIComponentBaseaddClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeBegin, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processRestoreState, processSaveState, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding, subscribeToEvent, unsubscribeFromEvent
 - 
Methods inherited from class jakarta.faces.component.UIComponentencodeAll, 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.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.omnifaces.validator.MultiFieldValidatorvalidateValues
 
- 
 
- 
- 
- 
Method Detail- 
validateHierarchyprotected void validateHierarchy() Validate our component hierarchy.- Specified by:
- validateHierarchyin class- ValidatorFamily
- Throws:
- IllegalStateException- When there is no parent of type- UIForm, or when there are any children.
 
 - 
validateComponentsprotected void validateComponents(FacesContext context) If the validation is not disabled, collect the components, if it is not empty, then collect their values and delegate toMultiFieldValidator.validateValues(FacesContext, List, List). If it returnsfalse, then mark all inputs and the faces context invalid and finally delegate toshowMessage(FacesContext, List)to show the message.- Specified by:
- validateComponentsin class- ValidatorFamily
- Parameters:
- context- The faces context to work with.
 
 - 
collectComponentsprotected List<UIInput> collectComponents() Collect the input components. Only those which are an instance ofUIInputwill be returned. If at least one of them has already been validated and is been marked invalid, then an empty collection will be returned.- Returns:
- The input components.
- Throws:
- IllegalArgumentException- When the- componentsattribute is missing, or when it references an non-existing component, or when it references a non-input component.
 
 - 
collectValuesprotected List<Object> collectValues(List<UIInput> inputs) Collect the values of the given input components.- Parameters:
- inputs- The input components to collect values from.
- Returns:
- The values of the given input components.
 
 - 
shouldInvalidateInputprotected boolean shouldInvalidateInput(FacesContext context, UIInput input, Object value) Returns whether in in an invalidating case the given input component should be marked invalid. The default implementation returnstrue, meaning that all input components should be invalidated in an invalidating case. The overriding implementation may choose to returnfalsefor example when the value is empty, such asValidateAllOrNone.- Parameters:
- context- The faces context to work with.
- input- The input component which may need to be invalidated.
- value- The value of the input component.
- Returns:
- Whether in in an invalidating case the given input component should be marked invalid
- Since:
- 1.7
 
 - 
showMessageprotected void showMessage(FacesContext context, List<UIInput> inputs) Show the message at the desired place(s) depending on the value of theshowMessageForattribute.- @this: message will be added to the- <h:message>for this component.
- @all: message will be added to all components as specified in- componentsattribute.
- Any other value in a space separated collection will be treated as client ID of UIInputcomponent.
 - Parameters:
- context- The faces context to work with.
- inputs- The validated input components.
 
 - 
getComponentspublic String getComponents() Returns the client identifiers of components which are to be validated.- Returns:
- The client identifiers of components which are to be validated.
 
 - 
setComponentspublic void setComponents(String components) Sets the client identifiers of components which are to be validated.- Parameters:
- components- The client identifiers of components which are to be validated.
 
 - 
isInvalidateAllpublic boolean isInvalidateAll() Returns whether to invalidate all fields or only those which are actually invalid as pershouldInvalidateInput(FacesContext, UIInput, Object)- Returns:
- Whether to invalidate all fields or only those which are actually invalid.
- Since:
- 1.7
 
 - 
setInvalidateAllpublic void setInvalidateAll(boolean invalidateAll) Sets whether to invalidate all fields or only those which are actually invalid as pershouldInvalidateInput(FacesContext, UIInput, Object)- Parameters:
- invalidateAll- Whether to invalidate all fields or only those which are actually invalid.
- Since:
- 1.7
 
 - 
getMessagepublic String getMessage() Returns the validation message to be shown.- Returns:
- The validation message to be shown.
 
 - 
setMessagepublic void setMessage(String message) Sets the validation message to be shown.- Parameters:
- message- The validation message to be shown.
 
 - 
getShowMessageForpublic String getShowMessageFor() Returns the client identifiers to show the validation message for.- Returns:
- The client identifiers to show the validation message for.
 
 - 
setShowMessageForpublic void setShowMessageFor(String showMessageFor) Sets the client identifiers to show the validation message for.- Parameters:
- showMessageFor- The client identifiers to show the validation message for.
 
 - 
isDisabledpublic boolean isDisabled() Returns whether the validation should be disabled or not.- Returns:
- Whether the validation should be disabled or not.
 
 - 
setDisabledpublic void setDisabled(boolean disabled) Sets whether the validation should be disabled or not.- Parameters:
- disabled- Whether the validation should be disabled or not.
 
 - 
isValidationFailedpublic boolean isValidationFailed() Returns whether the validation has failed or not.- Returns:
- Whether the validation has failed or not.
- Since:
- 1.3
 
 
- 
 
-