Java/Swing 中表单的声明式验证
我使用 Java 和 Swing 进行客户端开发。 我爱摇摆; 我相信它是那里最好的 GUI 框架之一。 然而,我怀念的是对声明性验证的支持。 就像 XForms 中的此片段。
您是否知道任何库允许以声明的方式验证表单中的数据输入,而不是通过为每个组件编写丑陋的验证文档侦听器?
I use Java for client-side development with Swing. I love Swing; I believe it is one of the better GUI frameworks there. What I miss, however, is the support for declarative validation. Like this snippet from XForms.
Do you know any library which allows validating data entry in forms in a declarative way, not by writing ugly validation document listeners for every component there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试 JSR 303 Bean 验证 的实现之一。 我认为它尚未最终确定,但有一些实现,例如
Hibernate Validator 和 Agimatec 验证。 我也没有尝试过,但阅读了一些有关如何使用 Bean Validation 的示例,这看起来很有希望。 这是采访 与规格领先。 我最喜欢该提案的是验证规则可以在不同层和不同框架中重用。 您可以选择注释和 xml 来进行“声明”。
最后,您可能想查看 Swing Java Builders,它提供了一种用于定义 GUI 和执行操作的声明式方法使用 Swing 进行验证和数据绑定。
You could try one of the implementations of JSR 303 Bean Validation. I don't think it is finalized yet but there are a few implementations around like
Hibernate Validator and Agimatec Validation. I haven't tried either but reading through some examples of how Bean Validation will be used makes it look promising. Here is an interview with the spec lead. What I like most about the proposal is that the validation rules can be reused in different layers and with different frameworks. You can choose between annotations and xml for doing the 'declaring'.
Lastly you might want to check out Swing Java Builders which provides a declarative way for defining GUIs and doing validation and data binding with Swing.
您可以看看我尝试构建一个 Swing GUI 构建器,该构建器使用 JSR303 验证和 Hibernate Validator: http://code.google.com/p/swing-formbuilder/
You may look at my attempt to build a Swing GUI builder, that uses JSR303 validation with Hibernate Validator: http://code.google.com/p/swing-formbuilder/
您只需编写一次丑陋的验证模型。 您可以以“声明性方式”使用它们。 实际有用的 Swing 库是一个更困难的问题。
You only have to write ugly validating models once. You can them use them in a "declarative way". Actual useful Swing libraries is a more difficult question.