Integrate JSR 303 - Bean Validation API
Tapestry provides a powerful validation mechanism which is described here. Among other things this mechanism allows you to annotate your domain model classes with the annotation @Validate. This annotation is problematic if your domain model is used in non-Tapestry applications as well as in Tapestry applications. Your non-Tapestry application becomes dependent on tapestry5-annotations. To make your domain model independent from Tapestry you can use the JSR 303: Bean Validation. This library provides integration between Tapestry and JSR-303.
Configuration
The Tapestry's JSR 303 - Bean Validation Library is responsible for configuring and bootstrapping the Validator for you. In order to use this library you have to choose an implementation of the JSR-303 specification like Hibernate Validator 4.x. This library is not specific to any implementation of JSR-303 and will work with any implementation of your choice.
Bootstraping the Bean Validator
The service BeanValidatorSource is responsible for bootstrapping the Validator. You can contribute a BeanValidatorConfigurer to the configuration of this service in order to participate on the configuration of Validator.
@Contribute(BeanValidatorSource.class) public static void provideBeanValidatorConfigurer(OrderedConfiguration<BeanValidatorConfigurer> configuration) { configuration.add("MyConfigurer", new BeanValidatorConfigurer() { public void configure(javax.validation.Configuration<?> configuration) { configuration.ignoreXmlConfiguration(); } }); }
Validation groups
In JSR-303 validation groups are used you to define a subset of the constraints validated at a given time. If no validation group is specified the default Defaul group is taken. By default Tapestry passes only this group to Validator. You can tell Tapestry to pass more groups by contributing group classes into the configuration of the BeanValidatorSource service.