GWT JSR 303 client validation

后端 未结 3 1668
后悔当初
后悔当初 2020-12-29 10:51

I\'m developing a GWT application with a Spring backend that uses JSR 303 validation. The application can go offline and use the browser HTML5/Gears database instead.

<
3条回答
  •  醉酒成梦
    2020-12-29 11:23

    Our validation framework is a client and server-side data input validation framework. Its roles is to ensure business rules compliance of data passed from the clients to the server.

    The validation framework uses the GWT Validation project which implements the "JSR 303: Bean Validation" specification.

    The idea is to decorate Data Transfer Objects (DTO) classes and fields with JSR303 annotations to describe their validity rules.

    1. Each Data Transfer Objects must be decorated with its own validation annotations.
    2. Each server-side service implementation must validate Data Transfer Objects it receives from the client.

    On the client side, to use GWT-Validation in your project you'll need to add (along with the jar on your classpath) to your GWT module xml file

    
    

    Ensure DTOs implement com.google.gwt.validation.client.interfaces.IValidatable

    To validate on the client side use

    com.google.gwt.validation.client.interfaces.IValidator.validateProperty((T) model, propertyName);
    

    On the server side use

    com.google.gwt.validation.server.ServerValidator
    

    It's a bit of work to set this up properly but then it works perfectly.

提交回复
热议问题