Class AnnotationValidationInterceptor
- All Implemented Interfaces:
com.opensymphony.xwork2.interceptor.ConditionalInterceptor
,com.opensymphony.xwork2.interceptor.Interceptor
,Serializable
,org.apache.struts2.interceptor.ConditionalInterceptor
,org.apache.struts2.interceptor.Interceptor
Struts 2 Interceptor for parsing annotated form fields from strings to another data type and writes error
messages where data type conversion fails. If the Action implements ModelDriven
, the model is recognised as
the form, not the action. Struts Actions are expected to implement ValidationAware
and, if message keys are
used, implement TextProvider
.
This differs from the standard ConversionErrorInterceptor by allowing writing to the general error list, not just field errors, and, if a message key is used, using the Action's text provider directly, not going through the Value Stack.
Interceptor parameters:
- None
Extending the interceptor:
Various points of the core algorithm can be overridden to customize behaviour. See javadoc of protected methods.
Example code:
<action name="someAction" class="com.examples.SomeAction"> <interceptor-ref name="annotationValidation"/> <interceptor-ref name="validation"/> <result name="success">good_result.ftl</result> </action>
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Deprecated.Describes a form field annotation, its type, and an instance of a policy it configures, if applicable.static class
Deprecated.Describes the result of a attempting to convert from a string to the generic type, and the field to receive it, successful or not.Nested classes/interfaces inherited from interface com.opensymphony.xwork2.interceptor.ConditionalInterceptor
com.opensymphony.xwork2.interceptor.ConditionalInterceptor.LegacyAdapter
-
Field Summary
Fields inherited from class com.opensymphony.xwork2.interceptor.MethodFilterInterceptor
excludeMethods, includeMethods
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
adjust
(Object form, Field formField, Annotation annotation, Adjuster<?> adjuster, String fieldValue) Deprecated.protected <T> void
checkCollectionConversionMessage
(Field unconvertedField, Annotation annotation, CollectionConverter<?, T> collectionConverter, AnnotationValidationInterceptor.ConversionFieldResult<T> conversionFieldResult, com.opensymphony.xwork2.interceptor.ValidationAware validationAware, com.opensymphony.xwork2.TextProvider textProvider) Deprecated.Checks if conversion results means a message must be written and writes appropriate type if needed.protected boolean
checkCollectionConversionRecipientDataType
(Field unconvertedField, Annotation annotation, Field recipientField, Class<?> recipientClass) Deprecated.Returns whether converting validator can convert form field value to the recipient field's type.protected <T> void
checkCollectionPostConversionMessage
(Field unconvertedField, Annotation annotation, CollectionPostConversionValidator<?, T> collectionPostConversionValidator, AnnotationValidationInterceptor.ConversionFieldResult<T> conversionFieldResult, ValidationResult validationResult, com.opensymphony.xwork2.interceptor.ValidationAware validationAware, com.opensymphony.xwork2.TextProvider textProvider) Deprecated.Checks if conversion results means a message must be written and writes appropriate type if needed.protected boolean
checkCollectionPostConversionRecipientDataType
(Annotation annotation, Field recipientField, Class<?> recipientClass) Deprecated.Returns whether post conversion validator can use the recipient field's type.protected <T> void
checkConversionMessage
(Field unconvertedField, Annotation annotation, Converter<?, T> converter, AnnotationValidationInterceptor.ConversionFieldResult<T> conversionFieldResult, com.opensymphony.xwork2.interceptor.ValidationAware validationAware, com.opensymphony.xwork2.TextProvider textProvider) Deprecated.Checks if conversion results means a message must be written and writes appropriate type if needed.protected boolean
checkConversionRecipientDataType
(Field unconvertedField, Annotation annotation, Field recipientField, Class<?> recipientClass) Deprecated.Returns whether converting validator can convert form field value to the recipient field's type.protected void
checkNonConversionMessage
(Field unconvertedField, Annotation annotation, NonConversionValidator<?> validator, ValidationResult validationResult, com.opensymphony.xwork2.interceptor.ValidationAware validationAware, com.opensymphony.xwork2.TextProvider textProvider) Deprecated.Checks if non-conversion validation results means a message must be written and writes appropriate type if needed.protected <T> void
checkPostConversionMessage
(Field unconvertedField, Annotation annotation, PostConversionValidator<?, T> postConversionValidator, AnnotationValidationInterceptor.ConversionFieldResult<T> conversionFieldResult, ValidationResult validationResult, com.opensymphony.xwork2.interceptor.ValidationAware validationAware, com.opensymphony.xwork2.TextProvider textProvider) Deprecated.Checks if conversion results means a message must be written and writes appropriate type if needed.protected boolean
checkPostConversionRecipientDataType
(Annotation annotation, Field recipientField, Class<?> recipientClass) Deprecated.Returns whether post conversion validator can use the recipient field's type.protected <T> AnnotationValidationInterceptor.ConversionFieldResult
<T> collectionConvert
(com.opensymphony.xwork2.ActionInvocation invocation, Object form, Collection<Field> allFormFields, Field formField, String fieldName, String fieldValue, AnnotationValidationInterceptor.AnnotationEntry<T> collectionConversionAnnotationEntry, boolean modelDriven) Deprecated.Converts form field value and returns result, or null if recipient field missing or compatibility checks fail.protected <T> Collection
<T> collectionPostConvertAdjust
(com.opensymphony.xwork2.ActionInvocation invocation, Object form, Field formField, Field recipientField, ConversionResult<T> conversionResult, Collection<T> parsedCollectionValue, AnnotationValidationInterceptor.AnnotationEntry<T> collectionPostConversionAdjusterAnnotationEntry, boolean modelDriven) Deprecated.Returns converted value adjusted by post conversion adjuster.protected <T> ValidationResult
collectionPostConvertValidate
(com.opensymphony.xwork2.ActionInvocation invocation, Object form, Field formField, Field recipientField, ConversionResult<T> conversionResult, Collection<T> parsedValue, AnnotationValidationInterceptor.AnnotationEntry<T> postConversionAnnotationEntry, boolean modelDriven) Deprecated.Return validation result of converted form field value, or null if compatibility checks fail.protected <T> AnnotationValidationInterceptor.ConversionFieldResult
<T> convert
(com.opensymphony.xwork2.ActionInvocation invocation, Object form, Collection<Field> allFormFields, Field formField, String fieldName, String fieldValue, AnnotationValidationInterceptor.AnnotationEntry<T> conversionAnnotationEntry, boolean modelDriven) Deprecated.Converts form field value and returns result, or null if recipient field missing or compatibility checks fail.protected String
doIntercept
(com.opensymphony.xwork2.ActionInvocation invocation) Deprecated.protected <T> InterceptorCommonLibrary.ConfiguredPolicy
<T> getAnnotationUsage
(Field unconvertedField, Annotation annotation) Deprecated.Returns validator (and formatter) that processes an annotated form field, or result of NA type if not recognised.protected <T> boolean
getCollectionPostConversionShortCircuit
(Field unconvertedField, AnnotationValidationInterceptor.AnnotationEntry<?> annotationEntry, Collection<T> parsedValue) Deprecated.Returns whether a rejection by the non-conversion validator should stop further validation.protected String
getDefaultRecipientName
(Field unconvertedField, String fieldName) Deprecated.Returns the default field name to receive a converted form field.protected String
getMessage
(com.opensymphony.xwork2.TextProvider textProvider, String messageKey, String message) Deprecated.Returns message to use, extracted from text provider if required.protected boolean
getNonConversionShortCircuit
(Field unconvertedField, AnnotationValidationInterceptor.AnnotationEntry<?> annotationEntry, String formValue) Deprecated.Returns whether a rejection by the non-conversion validator should stop further validation.protected <T> boolean
getPostConversionShortCircuit
(Field unconvertedField, AnnotationValidationInterceptor.AnnotationEntry<?> annotationEntry, T parsedValue) Deprecated.Returns whether a rejection by the non-conversion validator should stop further validation.static Collection
<Field> getProperties
(Class<?> type) Deprecated.Returns all member fields of a class, whether directly declared by the class or inherited.protected Field
getRecipientField
(Field unconvertedField, Annotation annotation, Collection<Field> fields, String recipientFieldName) Deprecated.Finds field to receive converted value from fields found in the form, or null if not found.protected <T> Collection
<T> makeCollectionForRecipient
(Class<?> recipientFieldClass) Deprecated.Returns an empty collection to set the recipient field and will accept converted values.protected <T> T
postConvertAdjust
(com.opensymphony.xwork2.ActionInvocation invocation, Object form, Field formField, Field recipientField, ConversionResult<T> conversionResult, T parsedValue, AnnotationValidationInterceptor.AnnotationEntry<T> postConversionAnnotationEntry, boolean modelDriven) Deprecated.Returns converted value adjusted by post conversion adjuster.protected <T> ValidationResult
postConvertValidate
(com.opensymphony.xwork2.ActionInvocation invocation, Object form, Field formField, Field recipientField, ConversionResult<T> conversionResult, T parsedValue, AnnotationValidationInterceptor.AnnotationEntry<T> postConversionAnnotationEntry, boolean modelDriven) Deprecated.Return validation result of converted form field value, or null if compatibility checks fail.protected <T> ConversionResult
<T> validateCollectionConversion
(Field unconvertedField, Annotation annotation, CollectionConverter<?, T> collectionConverter, String formValue, Field recipientField, Class<T> recipientClass) Deprecated.Calls validator to convert string form field value to recipient field of expected data type.protected <T> ValidationResult
validateCollectionPostConversion
(Field unconvertedField, Annotation annotation, CollectionPostConversionValidator<?, T> collectionPostConversionValidator, Collection<T> convertedValue, Field recipientField, Class<?> recipientClass) Deprecated.Calls validator to check a converted form field.protected <T> ConversionResult
<T> validateConversion
(Field unconvertedField, Annotation annotation, Converter<?, T> converter, String fieldValue, Field recipientField, Class<T> recipientClass) Deprecated.Calls validator to convert string form field value to recipient field of expected data type.protected ValidationResult
validateNonConversion
(Field unconvertedField, AnnotationValidationInterceptor.AnnotationEntry<?> annotationEntry, String fieldValue) Deprecated.Calls validator to check a form field before any conversion.protected <T> ValidationResult
validatePostConversion
(Field unconvertedField, Annotation annotation, PostConversionValidator<?, T> postConversionValidator, T convertedValue, Field recipientField, Class<T> recipientClass) Deprecated.Calls validator to check a converted form field.protected void
writeFieldError
(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String fieldName, String message) Deprecated.Writes message to Action's field errors for field.protected void
writeGeneralError
(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String message) Deprecated.Writes message to Action's action errors.protected void
writeInfoMessage
(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String message) Deprecated.Writes message to Action's action messages.protected void
writeWarningMessage
(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String message) Deprecated.Writes message to Action's action warnings.Methods inherited from class com.opensymphony.xwork2.interceptor.MethodFilterInterceptor
applyInterceptor, getExcludeMethodsSet, getIncludeMethodsSet, intercept, setExcludeMethods, setIncludeMethods
Methods inherited from class com.opensymphony.xwork2.interceptor.AbstractInterceptor
intercept, shouldIntercept, shouldIntercept
Methods inherited from class org.apache.struts2.interceptor.AbstractInterceptor
destroy, init, setDisabled
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.struts2.interceptor.Interceptor
destroy, init
-
Constructor Details
-
AnnotationValidationInterceptor
public AnnotationValidationInterceptor()Deprecated.
-
-
Method Details
-
getProperties
Deprecated.Returns all member fields of a class, whether directly declared by the class or inherited. -
adjust
protected String adjust(Object form, Field formField, Annotation annotation, Adjuster<?> adjuster, String fieldValue) throws Exception Deprecated. -
checkCollectionConversionMessage
protected <T> void checkCollectionConversionMessage(Field unconvertedField, Annotation annotation, CollectionConverter<?, T> collectionConverter, AnnotationValidationInterceptor.ConversionFieldResult<T> conversionFieldResult, com.opensymphony.xwork2.interceptor.ValidationAware validationAware, com.opensymphony.xwork2.TextProvider textProvider) Deprecated.Checks if conversion results means a message must be written and writes appropriate type if needed. -
checkCollectionConversionRecipientDataType
protected boolean checkCollectionConversionRecipientDataType(Field unconvertedField, Annotation annotation, Field recipientField, Class<?> recipientClass) Deprecated.Returns whether converting validator can convert form field value to the recipient field's type. -
checkCollectionPostConversionMessage
protected <T> void checkCollectionPostConversionMessage(Field unconvertedField, Annotation annotation, CollectionPostConversionValidator<?, T> collectionPostConversionValidator, AnnotationValidationInterceptor.ConversionFieldResult<T> conversionFieldResult, ValidationResult validationResult, com.opensymphony.xwork2.interceptor.ValidationAware validationAware, com.opensymphony.xwork2.TextProvider textProvider) Deprecated.Checks if conversion results means a message must be written and writes appropriate type if needed. -
checkCollectionPostConversionRecipientDataType
protected boolean checkCollectionPostConversionRecipientDataType(Annotation annotation, Field recipientField, Class<?> recipientClass) Deprecated.Returns whether post conversion validator can use the recipient field's type. -
checkConversionMessage
protected <T> void checkConversionMessage(Field unconvertedField, Annotation annotation, Converter<?, T> converter, AnnotationValidationInterceptor.ConversionFieldResult<T> conversionFieldResult, com.opensymphony.xwork2.interceptor.ValidationAware validationAware, com.opensymphony.xwork2.TextProvider textProvider) Deprecated.Checks if conversion results means a message must be written and writes appropriate type if needed. -
checkConversionRecipientDataType
protected boolean checkConversionRecipientDataType(Field unconvertedField, Annotation annotation, Field recipientField, Class<?> recipientClass) Deprecated.Returns whether converting validator can convert form field value to the recipient field's type. -
checkNonConversionMessage
protected void checkNonConversionMessage(Field unconvertedField, Annotation annotation, NonConversionValidator<?> validator, ValidationResult validationResult, com.opensymphony.xwork2.interceptor.ValidationAware validationAware, com.opensymphony.xwork2.TextProvider textProvider) Deprecated.Checks if non-conversion validation results means a message must be written and writes appropriate type if needed. -
checkPostConversionRecipientDataType
protected boolean checkPostConversionRecipientDataType(Annotation annotation, Field recipientField, Class<?> recipientClass) Deprecated.Returns whether post conversion validator can use the recipient field's type. -
checkPostConversionMessage
protected <T> void checkPostConversionMessage(Field unconvertedField, Annotation annotation, PostConversionValidator<?, T> postConversionValidator, AnnotationValidationInterceptor.ConversionFieldResult<T> conversionFieldResult, ValidationResult validationResult, com.opensymphony.xwork2.interceptor.ValidationAware validationAware, com.opensymphony.xwork2.TextProvider textProvider) Deprecated.Checks if conversion results means a message must be written and writes appropriate type if needed. -
collectionConvert
protected <T> AnnotationValidationInterceptor.ConversionFieldResult<T> collectionConvert(com.opensymphony.xwork2.ActionInvocation invocation, Object form, Collection<Field> allFormFields, Field formField, String fieldName, String fieldValue, AnnotationValidationInterceptor.AnnotationEntry<T> collectionConversionAnnotationEntry, boolean modelDriven) Deprecated.Converts form field value and returns result, or null if recipient field missing or compatibility checks fail. -
collectionPostConvertAdjust
protected <T> Collection<T> collectionPostConvertAdjust(com.opensymphony.xwork2.ActionInvocation invocation, Object form, Field formField, Field recipientField, ConversionResult<T> conversionResult, Collection<T> parsedCollectionValue, AnnotationValidationInterceptor.AnnotationEntry<T> collectionPostConversionAdjusterAnnotationEntry, boolean modelDriven) throws Exception Deprecated.Returns converted value adjusted by post conversion adjuster.- Throws:
Exception
-
collectionPostConvertValidate
protected <T> ValidationResult collectionPostConvertValidate(com.opensymphony.xwork2.ActionInvocation invocation, Object form, Field formField, Field recipientField, ConversionResult<T> conversionResult, Collection<T> parsedValue, AnnotationValidationInterceptor.AnnotationEntry<T> postConversionAnnotationEntry, boolean modelDriven) throws Exception Deprecated.Return validation result of converted form field value, or null if compatibility checks fail.- Throws:
Exception
-
convert
protected <T> AnnotationValidationInterceptor.ConversionFieldResult<T> convert(com.opensymphony.xwork2.ActionInvocation invocation, Object form, Collection<Field> allFormFields, Field formField, String fieldName, String fieldValue, AnnotationValidationInterceptor.AnnotationEntry<T> conversionAnnotationEntry, boolean modelDriven) Deprecated.Converts form field value and returns result, or null if recipient field missing or compatibility checks fail. -
doIntercept
Deprecated.- Specified by:
doIntercept
in classcom.opensymphony.xwork2.interceptor.MethodFilterInterceptor
- Throws:
Exception
-
getAnnotationUsage
protected <T> InterceptorCommonLibrary.ConfiguredPolicy<T> getAnnotationUsage(Field unconvertedField, Annotation annotation) throws Exception Deprecated.Returns validator (and formatter) that processes an annotated form field, or result of NA type if not recognised.- Throws:
Exception
-
getCollectionPostConversionShortCircuit
protected <T> boolean getCollectionPostConversionShortCircuit(Field unconvertedField, AnnotationValidationInterceptor.AnnotationEntry<?> annotationEntry, Collection<T> parsedValue) Deprecated.Returns whether a rejection by the non-conversion validator should stop further validation. -
getDefaultRecipientName
Deprecated.Returns the default field name to receive a converted form field. -
getMessage
protected String getMessage(com.opensymphony.xwork2.TextProvider textProvider, String messageKey, String message) Deprecated.Returns message to use, extracted from text provider if required. textProvider can be null if Action does not implement it. -
getNonConversionShortCircuit
protected boolean getNonConversionShortCircuit(Field unconvertedField, AnnotationValidationInterceptor.AnnotationEntry<?> annotationEntry, String formValue) Deprecated.Returns whether a rejection by the non-conversion validator should stop further validation. -
getPostConversionShortCircuit
protected <T> boolean getPostConversionShortCircuit(Field unconvertedField, AnnotationValidationInterceptor.AnnotationEntry<?> annotationEntry, T parsedValue) Deprecated.Returns whether a rejection by the non-conversion validator should stop further validation. -
getRecipientField
protected Field getRecipientField(Field unconvertedField, Annotation annotation, Collection<Field> fields, String recipientFieldName) Deprecated.Finds field to receive converted value from fields found in the form, or null if not found. -
makeCollectionForRecipient
Deprecated.Returns an empty collection to set the recipient field and will accept converted values. -
postConvertAdjust
protected <T> T postConvertAdjust(com.opensymphony.xwork2.ActionInvocation invocation, Object form, Field formField, Field recipientField, ConversionResult<T> conversionResult, T parsedValue, AnnotationValidationInterceptor.AnnotationEntry<T> postConversionAnnotationEntry, boolean modelDriven) throws Exception Deprecated.Returns converted value adjusted by post conversion adjuster.- Throws:
Exception
-
postConvertValidate
protected <T> ValidationResult postConvertValidate(com.opensymphony.xwork2.ActionInvocation invocation, Object form, Field formField, Field recipientField, ConversionResult<T> conversionResult, T parsedValue, AnnotationValidationInterceptor.AnnotationEntry<T> postConversionAnnotationEntry, boolean modelDriven) throws Exception Deprecated.Return validation result of converted form field value, or null if compatibility checks fail.- Throws:
Exception
-
validateCollectionConversion
protected <T> ConversionResult<T> validateCollectionConversion(Field unconvertedField, Annotation annotation, CollectionConverter<?, T> collectionConverter, String formValue, Field recipientField, Class<T> recipientClass) throws ExceptionDeprecated.Calls validator to convert string form field value to recipient field of expected data type.- Throws:
Exception
-
validateCollectionPostConversion
protected <T> ValidationResult validateCollectionPostConversion(Field unconvertedField, Annotation annotation, CollectionPostConversionValidator<?, T> collectionPostConversionValidator, Collection<T> convertedValue, Field recipientField, Class<?> recipientClass) throws ExceptionDeprecated.Calls validator to check a converted form field.- Throws:
Exception
-
validateConversion
protected <T> ConversionResult<T> validateConversion(Field unconvertedField, Annotation annotation, Converter<?, T> converter, String fieldValue, Field recipientField, Class<T> recipientClass) throws ExceptionDeprecated.Calls validator to convert string form field value to recipient field of expected data type.- Throws:
Exception
-
validateNonConversion
protected ValidationResult validateNonConversion(Field unconvertedField, AnnotationValidationInterceptor.AnnotationEntry<?> annotationEntry, String fieldValue) throws Exception Deprecated.Calls validator to check a form field before any conversion.- Throws:
Exception
-
validatePostConversion
protected <T> ValidationResult validatePostConversion(Field unconvertedField, Annotation annotation, PostConversionValidator<?, T> postConversionValidator, T convertedValue, Field recipientField, Class<T> recipientClass) throws ExceptionDeprecated.Calls validator to check a converted form field.- Throws:
Exception
-
writeFieldError
protected void writeFieldError(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String fieldName, String message) Deprecated.Writes message to Action's field errors for field. ValidationAware can be null if Action does not implement it. -
writeGeneralError
protected void writeGeneralError(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String message) Deprecated.Writes message to Action's action errors. ValidationAware can be null if Action does not implement it. -
writeInfoMessage
protected void writeInfoMessage(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String message) Deprecated.Writes message to Action's action messages. ValidationAware can be null if Action does not implement it. -
writeWarningMessage
protected void writeWarningMessage(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String message) Deprecated.Writes message to Action's action warnings. ValidationAware can be null if Action does not implement it.
-
AnnotationValidationInterceptor2
, which recognises this and other modes.