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
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BeanValidationManager
protected String
protected boolean
protected TextProviderFactory
Fields inherited from class org.apache.struts2.interceptor.MethodFilterInterceptor
excludeMethods, includeMethods
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected 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 DefaultActionInvocationprotected 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 actionErrorsprotected 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
-
Field Details
-
beanValidationManager
-
textProviderFactory
-
convertToUtf8
protected boolean convertToUtf8 -
convertFromEncoding
-
-
Constructor Details
-
BeanValidationInterceptor
public BeanValidationInterceptor()
-
-
Method Details
-
setBeanValidationManager
-
setTextProviderFactory
-
setConvertToUtf8
-
setConvertFromEncoding
-
doIntercept
- Specified by:
doIntercept
in classMethodFilterInterceptor
- Throws:
Exception
-
getValidationGroups
protected Class<?>[] getValidationGroups(Object action, String methodName) throws NoSuchMethodException - Throws:
NoSuchMethodException
-
performBeanValidation
-
addBeanValidationErrors
-
buildBeanValidationError
-
isActionError
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 classmethodName
- the method name- Returns:
- Method
- Throws:
NoSuchMethodException
- if no method with this name was found
-