问题标签 [hibernate-validator]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - 测试验证约束
Hibernate Validator 文档有一个简单的入门指南,其中概述了测试验证规则。
相关的块是
在我看来,测试 NotNull 约束是否被违反是一条相当模糊的路线。
我的简单解决方案类似于
这让我可以做类似的测试
但是,我确信从长远来看这将是幼稚的,并且我想知道是否没有其他库或 API 可以帮助进行单元测试约束。
hibernate - @Max 和@DecimalMax(以及@Min 和@DecimalMin)之间的区别
Hibernate Validator 中的@Max
and@DecimalMax
和@Min
and有什么区别?@DecimalMin
查看 Javadocs,他们似乎在执行相同的约束。
validation - Spring 3 验证和国际化
我使用这个链接来配置我的项目的验证: Spring 3 Validation
我添加了以下依赖项:
它工作正常,但我有一个国际化问题,我使用的是中文,但我发现 hibernate-validator-4.1.0.Final.jar 中不存在 zh_CN。还有其他选择吗?谢谢。
java - How do I apply AOP advice to a ConstraintValidator in Spring?
I am attempting to write my own Validator
(as per the JSR-303 specification) under Spring 3.0.x.
I annotated the isValid(Serializable, CosntraintValidatorContext)
method with @Transactional
, but it seems that transactional advice is not being applied to this method - when the isValid()
method is invoked, a call to sessionFactory.getCurrentSession()
creates the Exception:
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
I have an @Autowired
sessionFactory
in the same Validator
bean which is injected without issues. My current workaround is to use openSession()
instead of getCurrentSession()
, but that involves manual transaction management which I would prefer to avoid.
Doing a stack trace in the constructor of my validator bean, it seems that my Validator
bean is being constructed via a call to the o.s.b.f.s.AbstractAutowireCapableBeanFactory.createBean()
. I assume this means that the factory is capable of populating @Autowired
fields in my Validator
, but it seems that it is not applying any transactional advice?
Thanks in advance for any help on this matter.
EDIT: If it is of any help, I have included a partial stacktrace (via create new Exception()
) that is logged in the constructor:
Transactional configuration appears to be correct (the STS IDE reports that the isValid()
method is properly advised by the transactional manager by org.springframework.transaction.interceptor.TransactionInterceptor.invoke
(with an @Component
annotation on the Validator itself)), but my understanding is that if the validation bean is created outside the normal lifecycle of the Spring container, then the advice will not be properly applied when validation is done during data binding.
java - 如何在 Spring MVC 中使用自定义日期属性编辑器验证日期
我已经在我的 java 类中设置了日期
这是我在控制器中使用的代码
我正在使用 JSR 注释和休眠来验证其他字段。
有什么方法可以使用注释来验证日期必须仅以 dd-mm-yyyy 格式
java - 如何在休眠验证器中为我的所有属性设置默认约束
我想自动@Valid
对我的所有属性施加约束。
例子:
我希望验证器认为所有属性都有@Valid
注释。
怎样才能做到这一点?
spring - 休眠验证和本地化错误消息?
hibernate,我想为 hibernate 注释提供本地化的错误消息,所以我创建了属性文件 ValidatorMessages.properties,ValidatorMessages_ar.properties
并将它们放在资源文件夹中,我正在使用 messageSource 从属性文件中读取:
在课堂上我使用类似的东西:
并且在调用验证器时我使用:
它适用于英语,它可以正确显示英语消息,但是当切换到阿拉伯语时,它仍然显示英语消息而不是阿拉伯语,尽管那
LocaleContextHolder.getLocale()
表示语言已更改并且是阿拉伯语,因此配置是否缺少某些内容或任何可能导致该问题的想法?
operator-precedence - 控制验证注释顺序?
一个字段有两个验证注解
观察
如果该字段留空,则产生的违规按顺序变化:
- 有时
@NotEmpty
首先违反 - 其他时候
@Length
首先违反
问题
Hibernate如何指定处理验证(注释)的顺序?可以自定义此验证顺序吗?
提前致谢。
java - Cross Field Validation with inline messaging in JSF with JSR 303
What's the best way to invoke class level JSR-303 constraints that do cross field validation from JSF and have the resulting messages get translated to a FacesMessage and be tied to a particular JSF component based on the PropertyPath in the ConstraintViolation?
rich:graphValidator is close, but it doesn't make use of the PropertyPath. Perhaps MyFaces extval could get me close, but there seems to be a whole extra layer of framework on time of bean-validation, so I avoided it.
Here's a simple example:
Picture a form where the information about the car and the driver are input. If the Driver had a license type of ROAD and the Car had a car type of RACE, it'd be ideal to see a resulting validation message be translated into a FacesMessage which is connected to the input for license type, since the message was added to that node using the fluent API of Bean Validation.
validation - Hibernate Validator 和 Spring Webflow 的问题
我正在尝试使用 Spring WebFlow 和 Hibernate Validator Annotations 验证表单,但我做错了。
如果我使用 Spring 验证方式(ValidationContext、MessageContext、validate${state} 等),一切正常,但我想使用 @Email、@NotEmpty 等 Hibernate Annotations。
我已经阅读了很多论坛,Spring 文档,但我不知道我做错了什么。
此时,这是我的视图状态和下一步操作代码:
这是 startSignup.jsp 代码:
这是 myproject.web.pojo.User POJO 代码:
(注意:如您所见,当我使用 Spring Validation(取消注释 validate 方法)时,表单验证成功)
最后,这是我的 SignupAction 代码:
当我使用 Hibernate Validation 时,流程到达 saveUser 方法,没有任何验证。
我正在使用 Spring 3:
- Spring 3.0.5.RELEASE
- Spring WebFlow 2.2.1.RELEASE
- 休眠验证器 4.0.2.GA
我做错了什么?
非常感谢你帮助我!:)