用于 Java 客户端验证的 GWT Validator 框架

发布于 2025-01-05 04:07:17 字数 229 浏览 1 评论 0原文

我一直在研究可以用来验证客户端和服务器端数据的更好框架。我知道在双方进行验证很重要。

因此,我遇到了一种称为 GWT 验证框架的东西,它可以在两侧进行验证。我的 JSP 很少。我必须在客户端验证用户填写的数据。但我还没有找到一个关于如何做到这一点的例子?谁能请教一下。

谢谢

PS:如果有人可以帮助提供一些更好的客户端验证方法(除了java脚本),我将不胜感激。

I have been researching on the better framework I could use to validate the data at client and server side. I know it is important to do validations at both the side.

I had thus come across something called GWT Validation Framework which can do validations at both the side. I have few JSP's. I have o validate the data filled in by user, at client side. But I haven't found a single example on how to do it? Can anyone please enlighten on the same.

Thank you

P.S: It would be grateful if someone could assist on some better client side validation methods(other than java script).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月下伊人醉 2025-01-12 04:07:17

GWT 支持将 javax.validation 编译到编译模块中,但如果不实际使用 GWT,它不会很容易使用。验证机制由 JSR-303 bean 验证提供支持,因此需要在客户端和服务器上查看 bean - 由 jsp 创建的 html 客户端页面是不够的,您需要创建并加载 GWT 模块到页面上。

在 GWT 中,您编写看起来像 Java 的内容,然后它会编译为 JavaScript。 JSR303 支持也被编译为 JavaScript,因此任何数量的客户端验证都是不够的 - 请参阅 为什么客户端验证还不够?有关更多说明 - 您的服务器还需要运行验证。

如果您尚未使用 GWT,那么 GWT 的验证对您的项目没有多大意义。如果您认为这一切对您有意义,请开始使用它 - 查看 http:// /www.gwtproject.org/doc/latest/DevGuideValidation.html 了解更多信息,示例项目位于 https://github.com/gwtproject/gwt/tree/master/samples/validation< /a> 一些来源。

GWT has support for compiling javax.validation into a compile module, but it isn't going to be easy to use without actually using GWT. The validation mechanism is powered by JSR-303 bean validations, and so needs to see the bean on both the client and on the server - a html client page created by a jsp isn't enough, you need to create and load a GWT module onto the page.

In GWT, you write what looks like Java, and it compiles to JavaScript. JSR303 support also gets compiled to javascript, so any amount of client side validation isn't enough - see Why is client-side validation not enough? for more explanation on that - your server also needs to run the validation.

If you are not already using GWT, then GWT's validation isn't going to make a lot of sense for your project. If you decide this all makes sense for you, then start using it - check out http://www.gwtproject.org/doc/latest/DevGuideValidation.html for more information and the sample project at https://github.com/gwtproject/gwt/tree/master/samples/validation for some source.

所谓喜欢 2025-01-12 04:07:17
  1. 对于客户端数据验证

我正在使用Putnami Web Toolkit (PWT)。
该框架符合 commons JSR-303 bean 验证注释。

您可以在此位置找到文档和实例:
http://pwt.putnami.org/#!Validation

  1. 用于服务器端数据验证

我正在使用 Hibernate 的 Bean Validation JSR-303 参考实现(版本 4.3.2-Final )。

下面是一个例子:

导入:

import java.util.HashSet;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validation;
import javax.validation.ValidationException;
import javax.validation.Validator;

代码:

final Set<ConstraintViolation<BeanToValidate>> violations = validator.validate(form);
        if (!violations.isEmpty()) {
            final Set<ConstraintViolation<?>> constraintViolations = new HashSet<ConstraintViolation<?>>(
                    violations);
            throw new ConstraintViolationException(constraintViolations);
        }
  1. For client side data validation

I am using Putnami Web Toolkit (PWT).
This framework is compliant with commons JSR-303 bean validation annotations.

You can find documentation and live example at this location :
http://pwt.putnami.org/#!Validation

  1. For server side data validation

I am using Hibernate's Bean Validation JSR-303 reference implementation ( version 4.3.2-Final ).

An example below :

imports :

import java.util.HashSet;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validation;
import javax.validation.ValidationException;
import javax.validation.Validator;

code :

final Set<ConstraintViolation<BeanToValidate>> violations = validator.validate(form);
        if (!violations.isEmpty()) {
            final Set<ConstraintViolation<?>> constraintViolations = new HashSet<ConstraintViolation<?>>(
                    violations);
            throw new ConstraintViolationException(constraintViolations);
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文