Class InterceptorCommonLibrary
java.lang.Object
name.matthewgreet.strutscommons.util.InterceptorCommonLibrary
Static functions used by validation Interceptors, form formating Interceptors and validators.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Summarises the list of recognised annotations of a form field.static enum
static class
static class
Describes a type of form field annotation and an instance of the policy it configures.static class
static enum
static class
static class
InterceptorCommonLibrary.PolicyEntry<A extends Annotation,
P extends Policy<A>> Describes table entry that finds a policy class from the annotation class that configures it. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncategoriseFormFields
(Collection<Field> formFields) Sets how each form field should be converted.static <T> boolean
checkCollectionRecipientDataType
(Field recipientField, Class<T> recipientClass) Returns whether converting validator can convert form field value to the recipient field's type.static boolean
checkFieldClass
(Class<?> conversionClass, Class<?> fieldClass) Returns whether a converter's target data type can convert to the form field's data type.static boolean
checkRecipientDataType
(Field recipientField, Class<?> recipientClass) Returns whether converting validator can convert form field value to the recipient field's type.static boolean
fieldIsNotForm
(Field actionField) Returns whether a viewer Action's member field is definitely not a form.static boolean
fieldReceivedStoredForm
(Field actionField) Returns whether field of an Action received a stored form.static Collection
<Field> filterNonConversionErrorFormFields
(Collection<Field> formFields, Map<String, com.opensymphony.xwork2.conversion.impl.ConversionData> conversionErrors) Returns form member fields that didn't have a conversion error.static Collection
<Field> filterPlausibleFormFields
(Collection<Field> formFields) Returns form member fields that can plausibly receive form data.static <T> void
formatCollectionFormField
(Object form, Collection<Field> allFormFields, Field formField, InterceptorCommonLibrary.ConfiguredPolicy<T> configuredPolicy) Sets text for not yet set form field.static <T> void
formatFormField
(Object form, Collection<Field> allFormFields, Field formField, InterceptorCommonLibrary.ConfiguredPolicy<T> configuredPolicy) Sets text for not yet set form field.Returns the formatted forms created byFormFormatterInterceptor
.static <T> InterceptorCommonLibrary.AnnotationEntries
<T> getAnnotationEntries
(Field formField) Returns all recognised annotations and their linked policies.static <T> InterceptorCommonLibrary.ConfiguredPolicy
<T> getAnnotationUsage
(Annotation annotation) Returns validator (and formatter) that processes an annotated form field, or result of NA type if not recognised.static CollectionConverter
<?, ?> Returns default collection converter for a collection form field or display field, or null if none available.static Converter
<?, ?> getDefaultConverter
(Field field) Returns default converter for a single value form field or display field, or null if none available.static String
getDefaultRecipientName
(String fieldName) Returns the default field name to receive a converted form field.static <A extends Annotation,
T>
Converter<A, T> getDefaultRecognisedConverter
(Class<? extends Converter<A, T>> converterClass, Class<? extends A> annotationClass) static Object
Returns the object expected to receive submitted form data on behalf of an Action.getFormFieldCategory
(InterceptorCommonLibrary.FieldUsage<?> fieldUsage) static <T> InterceptorCommonLibrary.FieldUsage
<T> getFormFieldUsage
(Field formField) Returns what policies should apply to a form field, such as conversion and validation, or throwsFormFieldAnnotationTypeMismatchException
if any annotation does not match the field's type.static List
<InterceptorCommonLibrary.PolicyEntry<?, ?>> Returns list of all built-in adjusters, converters, and validators.static Collection
<Field> getProperties
(Class<?> type) Returns all properties of a class, even private ones, whether directly declared or inherited.static Field
getProperty
(Class<?> type, String name) Returns property of a class, even if private or inherited, or null if not found.Returns a processed form stored in session.static <T> Class
<T> getTypeFromCollectionField
(Field recipientField) Returns element type of a collection-based form field.static <T> Collection
<T> makeCollectionForRecipient
(Class<?> recipientClass) Returns an empty, modifiable collection from a collection type.
-
Constructor Details
-
InterceptorCommonLibrary
public InterceptorCommonLibrary()
-
-
Method Details
-
categoriseFormFields
public static <T> InterceptorCommonLibrary.CategoriseFieldResult categoriseFormFields(Collection<Field> formFields) Sets how each form field should be converted. -
checkCollectionRecipientDataType
public static <T> boolean checkCollectionRecipientDataType(Field recipientField, Class<T> recipientClass) Returns whether converting validator can convert form field value to the recipient field's type. -
checkFieldClass
Returns whether a converter's target data type can convert to the form field's data type. -
checkRecipientDataType
Returns whether converting validator can convert form field value to the recipient field's type. -
fieldIsNotForm
Returns whether a viewer Action's member field is definitely not a form. -
fieldReceivedStoredForm
Returns whether field of an Action received a stored form. -
filterNonConversionErrorFormFields
public static Collection<Field> filterNonConversionErrorFormFields(Collection<Field> formFields, Map<String, com.opensymphony.xwork2.conversion.impl.ConversionData> conversionErrors) Returns form member fields that didn't have a conversion error. -
filterPlausibleFormFields
Returns form member fields that can plausibly receive form data. This excludes static and final fields. -
formatCollectionFormField
public static <T> void formatCollectionFormField(Object form, Collection<Field> allFormFields, Field formField, InterceptorCommonLibrary.ConfiguredPolicy<T> configuredPolicy) Sets text for not yet set form field. -
formatFormField
public static <T> void formatFormField(Object form, Collection<Field> allFormFields, Field formField, InterceptorCommonLibrary.ConfiguredPolicy<T> configuredPolicy) Sets text for not yet set form field. -
getActionContextFormattedForms
Returns the formatted forms created byFormFormatterInterceptor
. As these are only created by a Struts 2 pre-result listener set by the Interceptor, no result is available till then. This is meant for the Interceptor and Actions should useStrutsMiscellaneousLibrary.getFormattedForms()
as it's easier to use. -
getAnnotationEntries
public static <T> InterceptorCommonLibrary.AnnotationEntries<T> getAnnotationEntries(Field formField) Returns all recognised annotations and their linked policies. -
getAnnotationUsage
public static <T> InterceptorCommonLibrary.ConfiguredPolicy<T> getAnnotationUsage(Annotation annotation) throws Exception Returns validator (and formatter) that processes an annotated form field, or result of NA type if not recognised.- Throws:
Exception
-
getDefaultCollectionConverter
Returns default collection converter for a collection form field or display field, or null if none available. -
getDefaultConverter
Returns default converter for a single value form field or display field, or null if none available. -
getDefaultRecognisedConverter
public static <A extends Annotation,T> Converter<A,T> getDefaultRecognisedConverter(Class<? extends Converter<A, T>> converterClass, Class<? extends A> annotationClass) -
getDefaultRecipientName
Returns the default field name to receive a converted form field. -
getForm
Returns the object expected to receive submitted form data on behalf of an Action. This can be the model of a ModelDriven Action, or the Action itself. -
getFormFieldCategory
public static InterceptorCommonLibrary.FormFieldCategory getFormFieldCategory(InterceptorCommonLibrary.FieldUsage<?> fieldUsage) -
getFormFieldUsage
public static <T> InterceptorCommonLibrary.FieldUsage<T> getFormFieldUsage(Field formField) throws FormFieldAnnotationTypeMismatchException Returns what policies should apply to a form field, such as conversion and validation, or throwsFormFieldAnnotationTypeMismatchException
if any annotation does not match the field's type. -
getPolicies
Returns list of all built-in adjusters, converters, and validators. -
getProperties
Returns all properties of a class, even private ones, whether directly declared or inherited. -
getProperty
Returns property of a class, even if private or inherited, or null if not found. -
getStoredForm
Returns a processed form stored in session. -
getTypeFromCollectionField
Returns element type of a collection-based form field. -
makeCollectionForRecipient
Returns an empty, modifiable collection from a collection type.
-