GWT JSR 303 客户端验证 [英] GWT JSR 303 client validation
问题描述
我正在开发一个带有使用 JSR 303 验证的 Spring 后端的 GWT 应用程序.该应用程序可以离线使用浏览器 HTML5/Gears 数据库.
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.
实现客户端验证的最佳方法是什么?到目前为止,我已经找到了 gwt-validation 框架(http://code.google.com/p/gwt-validation/) 但它似乎不再处于活动状态.
What is the best way to implement the client validation? So far I have found gwt-validation framework (http://code.google.com/p/gwt-validation/) but it seems it is no longer active.
谢谢!
更新:
有一个新的 GWT 官方项目来支持 JSR 303 Bean 验证 (链接在这里).一旦项目足够成熟,IMO 这就是要走的路.
There is a new GWT official project to support JSR 303 Bean Validation (link here). IMO this is the way to go once the project is mature enough.
推荐答案
我们的验证框架是一个客户端和服务器端数据输入验证框架.它的作用是确保从客户端传递到服务器的数据符合业务规则.
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.
验证框架使用实现JSR 303:Bean 验证"规范的 GWT 验证项目.
The validation framework uses the GWT Validation project which implements the "JSR 303: Bean Validation" specification.
这个想法是用 JSR303 注释来修饰数据传输对象 (DTO) 类和字段,以描述它们的有效性规则.
The idea is to decorate Data Transfer Objects (DTO) classes and fields with JSR303 annotations to describe their validity rules.
- 每个数据传输对象都必须使用自己的验证注释进行修饰.
- 每个服务器端服务实现都必须验证它从客户端收到的数据传输对象.
在客户端,要在您的项目中使用 GWT-Validation,您需要将(连同类路径上的 jar)添加到您的 GWT 模块 xml 文件中
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
<inherits name="com.google.gwt.validation.Validation" />
确保 DTO 实施 com.google.gwt.validation.client.interfaces.IValidatable
Ensure DTOs implement com.google.gwt.validation.client.interfaces.IValidatable
在客户端使用验证
com.google.gwt.validation.client.interfaces.IValidator.validateProperty((T) model, propertyName);
在服务器端使用
com.google.gwt.validation.server.ServerValidator
正确设置它需要一些工作,但它可以完美运行.
It's a bit of work to set this up properly but then it works perfectly.
这篇关于GWT JSR 303 客户端验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!