Class PropertyValidator<T>
- java.lang.Object
-
- org.apache.wicket.behavior.Behavior
-
- org.apache.wicket.bean.validation.PropertyValidator<T>
-
- Type Parameters:
T
-
- All Implemented Interfaces:
Serializable
,IComponentAwareEventSink
,IComponentAwareHeaderContributor
,IClusterable
,INullAcceptingValidator<T>
,IValidator<T>
public class PropertyValidator<T> extends Behavior implements INullAcceptingValidator<T>
Validator that delegates to the bean validation framework. The integration has to be first configured usingBeanValidationConfiguration
.The validator must be provided a
Property
, unless one can be resolved from the component implicitly. By default the configuration contains theDefaultPropertyResolver
soPropertyModel
s are supported out of the box - when attached to a component with a property model the property does not need to be specified explicitly.The validator will set the required flag on the form component it is attached to based on the presence of the @NotNull annotation, see
BeanValidationContext.isRequiredConstraint(ConstraintDescriptor)
for details. Notice, the required flag will only be set totrue
, components with the required flag already set totrue
will not have the flag set tofalse
by this validator.The validator will allow
ITagModifier
s registered onBeanValidationContext
to mutate the markup tag of the component it is attached to, e.g. add amaxlength
attribute.The validator specifies default error messages in the
PropertyValidator.properties
file. These values can be overridden in the application subclass' property files globally or in the page or panel properties locally. See this file for the default messages supported.- Author:
- igor
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description PropertyValidator(Class<?>... groups)
PropertyValidator(Property property, Class<?>... groups)
PropertyValidator(Property property, IModel<Class<?>[]> groups)
PropertyValidator(IModel<Class<?>[]> groups)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bind(Component component)
Bind this handler to the given component.void
detach(Component component)
Allows the behavior to detach any state it has attached during request processing.protected boolean
isRequired()
Should this property make the owning component required.void
onComponentTag(Component component, ComponentTag tag)
Called any time a component that has this behavior registered is rendering the component tag.void
onConfigure(Component component)
Called immediately after the onConfigure method in a component.void
validate(IValidatable<T> validatable)
Validates theIValidatable
instance.-
Methods inherited from class org.apache.wicket.behavior.Behavior
afterRender, beforeRender, canCallListener, getStatelessHint, isEnabled, isTemporary, onAttribute, onEvent, onException, onRemove, onTag, renderHead, unbind
-
-
-
-
Constructor Detail
-
PropertyValidator
public PropertyValidator(Class<?>... groups)
-
PropertyValidator
public PropertyValidator(IModel<Class<?>[]> groups)
-
PropertyValidator
public PropertyValidator(Property property, Class<?>... groups)
-
PropertyValidator
public PropertyValidator(Property property, IModel<Class<?>[]> groups)
-
-
Method Detail
-
bind
public void bind(Component component)
Description copied from class:Behavior
Bind this handler to the given component. This method is called by the host component immediately after this behavior is added to it. This method is useful if you need to do initialization based on the component it is attached and you can't wait to do it at render time. Keep in mind that if you decide to keep a reference to the host component, it is not thread safe anymore, and should thus only be used in situations where you do not reuse the behavior for multiple components.
-
onConfigure
public void onConfigure(Component component)
Description copied from class:Behavior
Called immediately after the onConfigure method in a component. Since this is before the rendering cycle has begun, the behavior can modify the configuration of the component (i.e. setVisible(false))- Overrides:
onConfigure
in classBehavior
- Parameters:
component
- the component being configured
-
detach
public void detach(Component component)
Description copied from class:Behavior
Allows the behavior to detach any state it has attached during request processing.
-
isRequired
protected boolean isRequired()
Should this property make the owning component required.- Returns:
true
if required- See Also:
BeanValidationContext.isRequiredConstraint(ConstraintDescriptor)
-
onComponentTag
public void onComponentTag(Component component, ComponentTag tag)
Description copied from class:Behavior
Called any time a component that has this behavior registered is rendering the component tag.- Overrides:
onComponentTag
in classBehavior
- Parameters:
component
- the component that renders this tag currentlytag
- the tag that is rendered
-
validate
public void validate(IValidatable<T> validatable)
Description copied from interface:IValidator
Validates theIValidatable
instance. Validation errors should be reported using theIValidatable.error(IValidationError)
method.- Specified by:
validate
in interfaceIValidator<T>
- Parameters:
validatable
- theIValidatable
instance being validated
-
-