Class ValidateMultiple

  • All Implemented Interfaces:
    PartialStateHolder, StateHolder, TransientStateHolder, ComponentSystemEventListener, FacesListener, SystemEventListenerHolder, EventListener, MultiFieldValidator

    public class ValidateMultiple
    extends ValidateMultipleFields

    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:
    ValidateMultipleHandler, ValidateMultipleFields, ValidatorFamily, MultiFieldValidator
    • Field Detail

      • COMPONENT_TYPE

        public static final String COMPONENT_TYPE
        The component type, which is "org.omnifaces.component.validator.ValidateMultiple".
        See Also:
        Constant Field Values
    • Constructor Detail

      • ValidateMultiple

        public ValidateMultiple()
    • Method Detail

      • validateValues

        public boolean validateValues​(FacesContext context,
                                      List<UIInput> components,
                                      List<Object> values)
        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:
        true if validation is successful, otherwise false (and thus show the message).
      • getValidator

        public MultiFieldValidator getValidator()
        Returns the validator instance.
        Returns:
        The validator instance.
      • setValidator

        public void setValidator​(MultiFieldValidator validator)
        Sets the validator instance.
        Parameters:
        validator - The validator instance.
      • getValidateMethod

        public MethodExpression getValidateMethod()
        Returns the validator method expression.
        Returns:
        The validator method expression.
      • setValidateMethod

        public void setValidateMethod​(MethodExpression validateMethod)
        Sets the validator method expression.
        Parameters:
        validateMethod - The validator method expression.