Skip to main content

Bean Validation with Apache Wicket

Posted by jjviana on October 5, 2011 at 6:13 PM PDT

Some Wicket goodies for my JavaOne talk.

If you go to my JavaOne 2011 talk "Productively Fun Web Development with Apache Wicket and Java EE 6" you will see a demo where Bean Validation is used in conjunction with Apache Wicket.

In order to accomplish that, all that you need is a single Java class that bridges the Wicket validation framework and the JSR 303 validation engine.

I am posting here not only this bridge class (JSR303Validator) but also two other utility classes: ValidationStyleBehaviour and BaseEntityForm.

ValidationStyleBehaviour is a Wicket behaviour that displays form component erros messages close to the form component itself, instead of in a FeedbackPanel.

BaseEntityForm is a Wicket Form that uses any class anotated with Bean Validation annotations and uses JSR303Validator and ValidationStyleBehaviour in every form field, so that the resulting form validates according to the constraints expressed by the annotations and renders validation messages nicely.

The results can be seen below:

 

You can download the code here.

 

AttachmentSize
JSR303Validation.zip3.04 KB
RegisterFormValidation.png121.63 KB