Class BeanValidationConfiguration
- java.lang.Object
-
- org.apache.wicket.bean.validation.BeanValidationConfiguration
-
- All Implemented Interfaces:
BeanValidationContext
,IPropertyResolver
public class BeanValidationConfiguration extends Object implements BeanValidationContext
Configures bean validation and integrates it with Wicket- Author:
- igor
-
-
Constructor Summary
Constructors Constructor Description BeanValidationConfiguration()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BeanValidationConfiguration
add(IPropertyResolver resolver)
Adds a property resolver to the configuration.void
configure(Application application)
Binds this configuration to the application instancestatic BeanValidationContext
get()
Retrieves the validation context (read only version of the configuration).<T extends Annotation>
ITagModifier<T>getTagModifier(Class<T> annotationType)
Get the registered modifier for the given annotation.javax.validation.Validator
getValidator()
IViolationTranslator
getViolationTranslator()
boolean
isRequiredConstraint(javax.validation.metadata.ConstraintDescriptor<?> constraint)
By defaultNotNull
andNotEmpty
constraints make a component required.<T extends Annotation>
BeanValidationConfigurationregister(Class<T> annotationType, ITagModifier<T> modifier)
Registers a tag modifier for a specific constraint annotation.Property
resolveProperty(FormComponent<?> component)
Resolve the property for a component.void
setValidatorProvider(Supplier<javax.validation.Validator> validatorProvider)
Sets the provider used to retrieveValidator
instancesvoid
setViolationTranslator(IViolationTranslator violationTranslator)
Registers a violation translator
-
-
-
Constructor Detail
-
BeanValidationConfiguration
public BeanValidationConfiguration()
-
-
Method Detail
-
register
public <T extends Annotation> BeanValidationConfiguration register(Class<T> annotationType, ITagModifier<T> modifier)
Registers a tag modifier for a specific constraint annotation.By default
Size
constraints are automatically mapped tomaxlength
of text inputs, this can be disabled by registering aITagModifier.NO_OP
instead:configuration.register(Size.class, ITagModifier.NO_OP});
- Parameters:
annotationType
- constraint annotation such asSize
modifier
- tag modifier to use- Returns:
this
-
getTagModifier
public <T extends Annotation> ITagModifier<T> getTagModifier(Class<T> annotationType)
Get the registered modifier for the given annotation.- Specified by:
getTagModifier
in interfaceBeanValidationContext
- Returns:
- tag modifier or
null
if none - See Also:
register(Class, ITagModifier)
-
add
public BeanValidationConfiguration add(IPropertyResolver resolver)
Adds a property resolver to the configuration. Property resolvers registered last are the first to be allowed to resolve the property.- Parameters:
resolver
-- Returns:
this
-
getValidator
public javax.validation.Validator getValidator()
- Specified by:
getValidator
in interfaceBeanValidationContext
- Returns:
- validator
-
setValidatorProvider
public void setValidatorProvider(Supplier<javax.validation.Validator> validatorProvider)
Sets the provider used to retrieveValidator
instances- Parameters:
validatorProvider
-
-
configure
public void configure(Application application)
Binds this configuration to the application instance- Parameters:
application
-
-
getViolationTranslator
public IViolationTranslator getViolationTranslator()
- Specified by:
getViolationTranslator
in interfaceBeanValidationContext
- Returns:
- registered violation translator
-
setViolationTranslator
public void setViolationTranslator(IViolationTranslator violationTranslator)
Registers a violation translator- Parameters:
violationTranslator
- A violation translator that will convertConstraintViolation
s into Wicket'sValidationError
s
-
get
public static BeanValidationContext get()
Retrieves the validation context (read only version of the configuration). This is how components retrieve the configuration.- Returns:
- validation context
-
resolveProperty
public Property resolveProperty(FormComponent<?> component)
Description copied from interface:BeanValidationContext
Resolve the property for a component.- Specified by:
resolveProperty
in interfaceBeanValidationContext
- Specified by:
resolveProperty
in interfaceIPropertyResolver
- Parameters:
component
- component
-
isRequiredConstraint
public boolean isRequiredConstraint(javax.validation.metadata.ConstraintDescriptor<?> constraint)
By defaultNotNull
andNotEmpty
constraints make a component required.- Specified by:
isRequiredConstraint
in interfaceBeanValidationContext
- Parameters:
constraint
- constraint- Returns:
true
if required
-
-