com.opensymphony.xwork2.validator.validators

## Class ConditionalVisitorFieldValidator

- java.lang.Object
- - com.opensymphony.xwork2.validator.validators.ValidatorSupport
  - - com.opensymphony.xwork2.validator.validators.FieldValidatorSupport
    - - com.opensymphony.xwork2.validator.validators.VisitorFieldValidator
      - - com.opensymphony.xwork2.validator.validators.ConditionalVisitorFieldValidator

- All Implemented Interfaces:
    FieldValidator, ShortCircuitableValidator, Validator

      public class ConditionalVisitorFieldValidator
      extends VisitorFieldValidator

  The ConditionalVisitorFieldValidator will forward validation to the VisitorFieldValidator only if the expression will evaluate to true.
  - expression - an OGNL expression which should evaluate to true to pass validation to the VisitorFieldValidator

       <field name="colleaguePosition">
           <field-validator type="conditionalvisitor">
               <param name="expression">reason == 'colleague' and colleaguePositionID == 'OTHER'</param>
               <message>You must select reason Colleague and position Other</message>
           </field-validator>
       </field>

  Author:
    Matt Raible

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class com.opensymphony.xwork2.validator.validators.VisitorFieldValidator

      `VisitorFieldValidator.AppendingValidatorContext`

  - ### Field Summary

    - ### Fields inherited from class com.opensymphony.xwork2.validator.validators.FieldValidatorSupport

      `currentValue, fieldName, type`

    - ### Fields inherited from class com.opensymphony.xwork2.validator.validators.ValidatorSupport

      `defaultMessage, EMPTY_STRING, messageKey, stack, textProviderFactory`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConditionalVisitorFieldValidator()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getExpression()`
    `void` | `setExpression(String expression)`
    `void` | `validate(Object object)` If expression evaluates to true, invoke visitor validation.
    `boolean` | `validateExpression(Object object)` Validate the expression contained in the "expression" paramter.

    - ### Methods inherited from class com.opensymphony.xwork2.validator.validators.VisitorFieldValidator

      `getContext, isAppendPrefix, setActionValidatorManager, setAppendPrefix, setContext`

    - ### Methods inherited from class com.opensymphony.xwork2.validator.validators.FieldValidatorSupport

      `getCurrentValue, getFieldName, getValidatorType, setFieldName, setValidatorType`

    - ### Methods inherited from class com.opensymphony.xwork2.validator.validators.ValidatorSupport

      `addActionError, addFieldError, getDefaultMessage, getFieldValue, getMessage, getMessageKey, getMessageParameters, getValidatorContext, isShortCircuit, parse, setDefaultMessage, setMessageKey, setMessageParameters, setShortCircuit, setTextProviderFactory, setValidatorContext, setValueStack`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.opensymphony.xwork2.validator.Validator

      `getDefaultMessage, getMessage, getMessageKey, getMessageParameters, getValidatorContext, setDefaultMessage, setMessageKey, setMessageParameters, setValidatorContext, setValueStack`

- - ### Constructor Detail

    - #### ConditionalVisitorFieldValidator

          public ConditionalVisitorFieldValidator()

  - ### Method Detail

    - #### setExpression

          public void setExpression(String expression)

    - #### getExpression

          public String getExpression()

    - #### validate

          public void validate(Object object)
                        throws ValidationException

      If expression evaluates to true, invoke visitor validation.
      Specified by:
        `validate` in interface `Validator`
      Overrides:
        `validate` in class `VisitorFieldValidator`
      Parameters:
        `object` - the object being validated
      Throws:
        `ValidationException` - in case of validation problems

    - #### validateExpression

          public boolean validateExpression(Object object)
                                     throws ValidationException

      Validate the expression contained in the "expression" paramter.
      Parameters:
        `object` - the object you're validating
      Returns:
        true if expression evaluates to true (implying a validation failure)
      Throws:
        `ValidationException` - if anything goes wrong

Copyright © 2000–2021 Apache Software Foundation. All rights reserved.