使用HibernateValidator在Spring MVC中发生某些事件时,在运行时动态关闭或禁止验证 [英] Turn off or disallow validation dynamically at run time when certain event occurs in Spring MVC using HibernateValidator

查看:128
本文介绍了使用HibernateValidator在Spring MVC中发生某些事件时,在运行时动态关闭或禁止验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

I'm using HibernateValidator to validate forms in JSP using Spring MVC 3.0.2. Earlier, I was using the Validator interface to validate forms where it was possible to disallow validation when certain event occurs.

为了演示起见,我在JSP页面上有一个表单,其中只有两个文本字段和一个提交按钮.当这些字段填充有适当的值并单击提交"按钮时,如果不违反任何验证规则,则将首先执行验证并将值插入数据库中.效果很好.

For the sake of demonstration, I have one form on a JSP page where there are only two text fields and a submit button. When those fields are filled with appropriate values and the submit button is clicked, validation is performed first and values are inserted into the database, if any validation rule is not violated. It works fine.

表单上还有其他提交按钮可以执行其他操作,例如更新和删除.因此,当单击此类按钮时,不需要在这些文本字段上进行验证,并且必须执行.发生某些此类事件时,是否可以在运行时关闭或禁止验证?

There are also other submit buttons on the form to perform other operations like update and delete. Therefore when such buttons are clicked, the validation on those text fields is unnecessary and must not be performed. Is there a way to turn off or disallow validation at run time when certain such events occur?

推荐答案

Jsr 303具有验证组的概念.这允许仅验证指定组的验证规则. 我敢肯定,我早就回答了这样的问题,但是目前我只有一部手机,所以搜索这个问题很麻烦

Jsr 303 has the concept of validation groups. This allows to validate validation rules of only a specified group. I am sure that I have answered a question like this on so some time ago, but at the moment I have only a mobile phone, so it is pain in the ass to search for this question

这篇关于使用HibernateValidator在Spring MVC中发生某些事件时,在运行时动态关闭或禁止验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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