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:
com.opensymphony.xwork2.interceptor.ConditionalInterceptor
,com.opensymphony.xwork2.interceptor.Interceptor
,Serializable
public class BeanValidationInterceptor
extends com.opensymphony.xwork2.interceptor.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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BeanValidationManager
protected String
protected boolean
protected com.opensymphony.xwork2.TextProviderFactory
Fields inherited from class com.opensymphony.xwork2.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
(com.opensymphony.xwork2.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
(com.opensymphony.xwork2.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
-
Field Details
-
beanValidationManager
-
textProviderFactory
protected com.opensymphony.xwork2.TextProviderFactory textProviderFactory -
convertToUtf8
protected boolean convertToUtf8 -
convertFromEncoding
-
-
Constructor Details
-
BeanValidationInterceptor
public BeanValidationInterceptor()
-
-
Method Details
-
setBeanValidationManager
-
setTextProviderFactory
public void setTextProviderFactory(com.opensymphony.xwork2.TextProviderFactory textProviderFactory) -
setConvertToUtf8
-
setConvertFromEncoding
-
doIntercept
- Specified by:
doIntercept
in classcom.opensymphony.xwork2.interceptor.MethodFilterInterceptor
- 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
-