Package org.apache.struts.beanvalidation.validation.interceptor

# Class BeanValidationInterceptor

java.lang.Object
org.apache.struts2.interceptor.AbstractInterceptor
org.apache.struts2.interceptor.MethodFilterInterceptor
org.apache.struts.beanvalidation.validation.interceptor.BeanValidationInterceptor

All Implemented Interfaces:
  `Serializable`, `ConditionalInterceptor`, `Interceptor`

public class BeanValidationInterceptor extends MethodFilterInterceptor

Bean Validation interceptor. This Interceptor does not itself provide any Bean validation functionality but works as a bridge between Bean validation implementations like Apache Bval or Hibernate Validator and Struts2 validation mechanism.

Interceptor will create a Validation Factory based on the provider class and will validate requested method or Action class. Hibernate bean validator will be used as a default validator in case of no provider class will be supplied to the interceptor.

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected BeanValidationManager`
  `beanValidationManager`
  `protected String`
  `convertFromEncoding`
  `protected boolean`
  `convertToUtf8`
  `protected TextProviderFactory`
  `textProviderFactory`

  ### Fields inherited from class org.apache.struts2.interceptor.MethodFilterInterceptor

  `excludeMethods, includeMethods`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BeanValidationInterceptor()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `addBeanValidationErrors(Set<jakarta.validation.ConstraintViolation<Object>> constraintViolations, Object action)`
  `protected org.apache.struts.beanvalidation.validation.interceptor.BeanValidationInterceptor.ValidationError`
  `buildBeanValidationError(jakarta.validation.ConstraintViolation<Object> violation, String message)`
  `protected String`
  `doIntercept(ActionInvocation invocation)`
  `protected Method`
  `getActionMethod(Class<?> actionClass, String methodName)`
  This is copied from DefaultActionInvocation
  `protected Class<?>[]`
  `getValidationGroups(Object action, String methodName)`
  `protected boolean`
  `isActionError(jakarta.validation.ConstraintViolation<Object> violation)`
  Decide if a violation should be added to the fieldErrors or actionErrors
  `protected void`
  `performBeanValidation(Object action, jakarta.validation.Validator validator, Class<?>[] groups)`
  `void`
  `setBeanValidationManager(BeanValidationManager beanValidationManager)`
  `void`
  `setConvertFromEncoding(String convertFromEncoding)`
  `void`
  `setConvertToUtf8(String convertToUtf8)`
  `void`
  `setTextProviderFactory(TextProviderFactory textProviderFactory)`

  ### Methods inherited from class org.apache.struts2.interceptor.MethodFilterInterceptor

  `applyInterceptor, getExcludeMethodsSet, getIncludeMethodsSet, intercept, setExcludeMethods, setIncludeMethods`

  ### Methods inherited from class org.apache.struts2.interceptor.AbstractInterceptor

  `destroy, init, setDisabled, shouldIntercept`

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

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

- ## Field Details

  - ### beanValidationManager

    protected BeanValidationManager beanValidationManager

  - ### textProviderFactory

    protected TextProviderFactory textProviderFactory

  - ### convertToUtf8

    protected boolean convertToUtf8

  - ### convertFromEncoding

    protected String convertFromEncoding

- ## Constructor Details

  - ### BeanValidationInterceptor

    public BeanValidationInterceptor()

- ## Method Details

  - ### setBeanValidationManager

    public void setBeanValidationManager(BeanValidationManager beanValidationManager)

  - ### setTextProviderFactory

    public void setTextProviderFactory(TextProviderFactory textProviderFactory)

  - ### setConvertToUtf8

    public void setConvertToUtf8(String convertToUtf8)

  - ### setConvertFromEncoding

    public void setConvertFromEncoding(String convertFromEncoding)

  - ### doIntercept

    protected String doIntercept(ActionInvocation invocation) throws Exception
    Specified by:
      `doIntercept` in class `MethodFilterInterceptor`
    Throws:
      `Exception`

  - ### getValidationGroups

    protected Class<?>[] getValidationGroups(Object action, String methodName) throws NoSuchMethodException
    Throws:
      `NoSuchMethodException`

  - ### performBeanValidation

    protected void performBeanValidation(Object action, jakarta.validation.Validator validator, Class<?>[] groups)

  - ### addBeanValidationErrors

    protected void addBeanValidationErrors(Set<jakarta.validation.ConstraintViolation<Object>> constraintViolations, Object action)

  - ### buildBeanValidationError

    protected org.apache.struts.beanvalidation.validation.interceptor.BeanValidationInterceptor.ValidationError buildBeanValidationError(jakarta.validation.ConstraintViolation<Object> violation, String message)

  - ### isActionError

    protected boolean isActionError(jakarta.validation.ConstraintViolation<Object> violation)
    Decide if a violation should be added to the fieldErrors or actionErrors
    Parameters:
      `violation` - the violation
    Returns:
      true if violation should be added to the fieldErrors or actionErrors

  - ### getActionMethod

    protected Method getActionMethod(Class<?> actionClass, String methodName) throws NoSuchMethodException
    This is copied from DefaultActionInvocation
    Parameters:
      `actionClass` - the action class
      `methodName` - the method name
    Returns:
      Method
    Throws:
      `NoSuchMethodException` - if no method with this name was found