org.apache.struts.beanvalidation.validation.interceptor

## Class BeanValidationInterceptor

- java.lang.Object
- - com.opensymphony.xwork2.interceptor.AbstractInterceptor
  - - com.opensymphony.xwork2.interceptor.MethodFilterInterceptor
    - - org.apache.struts.beanvalidation.validation.interceptor.BeanValidationInterceptor

- All Implemented Interfaces:
    ConditionalInterceptor, Interceptor, Serializable

      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 and Description
    --- | ---
    `protected BeanValidationManager` | `beanValidationManager`
    `protected String` | `convertFromEncoding`
    `protected boolean` | `convertToUtf8`
    `protected TextProviderFactory` | `textProviderFactory`

    - ### Fields inherited from class com.opensymphony.xwork2.interceptor.MethodFilterInterceptor

      `excludeMethods, includeMethods`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BeanValidationInterceptor()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addBeanValidationErrors(Set<javax.validation.ConstraintViolation<Object>> constraintViolations, Object action)`
    `protected org.apache.struts.beanvalidation.validation.interceptor.BeanValidationInterceptor.ValidationError` | `buildBeanValidationError(javax.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(javax.validation.ConstraintViolation<Object> violation)` Decide if a violation should be added to the fieldErrors or actionErrors
    `protected void` | `performBeanValidation(Object action, javax.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 com.opensymphony.xwork2.interceptor.MethodFilterInterceptor

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

    - ### Methods inherited from class com.opensymphony.xwork2.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 Detail

    - #### beanValidationManager

          protected BeanValidationManager beanValidationManager

    - #### textProviderFactory

          protected TextProviderFactory textProviderFactory

    - #### convertToUtf8

          protected boolean convertToUtf8

    - #### convertFromEncoding

          protected String convertFromEncoding

  - ### Constructor Detail

    - #### BeanValidationInterceptor

          public BeanValidationInterceptor()

  - ### Method Detail

    - #### 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,
                                               javax.validation.Validator validator,
                                               Class<?>[] groups)

    - #### addBeanValidationErrors

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

    - #### buildBeanValidationError

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

    - #### isActionError

          protected boolean isActionError(javax.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

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