Turn off or disallow validation dynamically at run time when certain event occurs in Spring MVC using HibernateValidator

爱⌒轻易说出口 提交于 2019-12-11 02:18:34

问题


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.

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?


回答1:


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



来源:https://stackoverflow.com/questions/11810688/turn-off-or-disallow-validation-dynamically-at-run-time-when-certain-event-occu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!