JSF / Hibernate NotBlank验证 [英] JSF/Hibernate NotBlank validation

查看:130
本文介绍了JSF / Hibernate NotBlank验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的JSF + RichFaces表单,其中包含一些字段,显然是一个支持bean来存储它们。在那个bean中,所有必需的属性都有验证注释(jsr303 / hibernate),但我似乎无法找到一个注释来检查属性(String)是否为空。我知道spring模块中有@NotBlank注释,但JSF不支持spring验证。有没有简单的方法来检查它还是我应该编写自己的注释?

I have a simple JSF+RichFaces form with some fields and obviously a backing bean to store them. In that bean all the necessary properties have validation annotations (jsr303/hibernate), but I can't seem to find an annotation which would check if the property (String) is blank. I know there's a @NotBlank annotation in spring modules, but JSF doesn't support spring validation. Is there any easy way to check it or should I write my own annotation?

@Edit:我已经尝试过来自jsr303和hibernate的@NotNull和@NotEmpty,但它们都是失败我仍然可以发送一个空字符串,如。

@ I already tried @NotNull and @NotEmpty from jsr303 and hibernate, but they both failed I still can send a blank string like " ".

推荐答案

如果你使用Hibernate Validator 4.1作为你的JSR-303实现,他们提供 @NotBlank 注释完全符合您的要求,与@NotNull和@NotEmpty分开。您需要使用(当前)最新版本,但这将有效。

If you use Hibernate Validator 4.1 as your JSR-303 implementation, they provide a @NotBlank annotation that does EXACTLY what you're looking for, separate from @NotNull and @NotEmpty. You need to be using the (currently) latest version, but that will work.

如果由于某种原因无法转到最新版本,则不会需要花很多时间自己写一个注释。

If you can't go to the latest version for some reason, it doesn't take much to write an annotation yourself.

这篇关于JSF / Hibernate NotBlank验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆