java.lang.Object
jakarta.faces.component.UIComponent
jakarta.faces.component.UIComponentBase
org.omnifaces.component.validator.ValidatorFamily
org.omnifaces.component.validator.ValidateMultipleFields
org.omnifaces.component.validator.ValidateMultiple
- All Implemented Interfaces:
PartialStateHolder,StateHolder,TransientStateHolder,ComponentSystemEventListener,FacesListener,SystemEventListenerHolder,EventListener,MultiFieldValidator
The <o:validateMultiple> allows the developer to validate multiple fields by either a custom
validator method:
<o:validateMultiple id="myId" components="foo bar baz" validator="#{bean.someMethod}" />
<h:message for="myId" />
<h:inputText id="foo" />
<h:inputText id="bar" />
<h:inputText id="baz" />
whereby the method has the following signature (method name is free to your choice):
public boolean someMethod(FacesContext context, List<UIInput> components, List<Object> values) {
// ...
}
Or, by a managed bean instance which implements the MultiFieldValidator interface:
<o:validateMultiple id="myId" components="foo bar baz" validator="#{validateValuesBean}" />
<h:message for="myId" />
<h:inputText id="foo" />
<h:inputText id="bar" />
<h:inputText id="baz" />
@ManagedBean
@RequestScoped
public class ValidateValuesBean implements MultiFieldValidator {
@Override
public boolean validateValues(FacesContext context, List<UIInput> components, List<Object> values) {
// ...
}
}
Design notice
Note that this validator does not throw ValidatorException, but returns a boolean! Message
handling and invalidation job is up to the ValidateMultipleFields implementation who will call this method.
You can customize the message by the message attribute of the tag. Refer ValidateMultipleFields
documentation for general usage instructions.
- Since:
- 1.7
- Author:
- Juliano Marques, Bauke Scholtz
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe component type, which is "org.omnifaces.component.validator.ValidateMultiple".Fields inherited from class org.omnifaces.component.validator.ValidatorFamily
COMPONENT_FAMILYFields 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 TypeMethodDescriptionReturns the validator method expression.Returns the validator instance.voidsetValidateMethod(MethodExpression validateMethod) Sets the validator method expression.voidsetValidator(MultiFieldValidator validator) Sets the validator instance.booleanvalidateValues(FacesContext context, List<UIInput> components, List<Object> values) Invoke the validator and return its outcome.Methods inherited from class org.omnifaces.component.validator.ValidateMultipleFields
collectComponents, collectValues, getComponents, getMessage, getShowMessageFor, isDisabled, isInvalidateAll, isValidationFailed, setComponents, setDisabled, setInvalidateAll, setMessage, setShowMessageFor, shouldInvalidateInput, showMessage, validateComponents, validateHierarchyMethods inherited from class org.omnifaces.component.validator.ValidatorFamily
encodeChildren, getFamily, getRendersChildren, processDecodes, processUpdates, processValidatorsMethods inherited from class jakarta.faces.component.UIComponentBase
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeAll, encodeBegin, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getPassThroughAttributes, getRenderer, getRendererType, invokeOnComponent, isRendered, isTransient, markInitialState, processRestoreState, processSaveState, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, 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, unsubscribeFromEvent
-
Field Details
-
COMPONENT_TYPE
The component type, which is "org.omnifaces.component.validator.ValidateMultiple".- See Also:
-
-
Constructor Details
-
ValidateMultiple
public ValidateMultiple()
-
-
Method Details
-
validateValues
Invoke the validator and return its outcome.- Parameters:
context- The faces context to work with.components- The input components whose values are to be validated.values- The values of the input components to be validated, in the same order as the components.- Returns:
trueif validation is successful, otherwisefalse(and thus show the message).
-
getValidator
Returns the validator instance.- Returns:
- The validator instance.
-
setValidator
Sets the validator instance.- Parameters:
validator- The validator instance.
-
getValidateMethod
Returns the validator method expression.- Returns:
- The validator method expression.
-
setValidateMethod
Sets the validator method expression.- Parameters:
validateMethod- The validator method expression.
-