如何使用 Struts2 验证进行条件验证? [英] How to use Struts2 validation for conditional validation?

查看:33
本文介绍了如何使用 Struts2 验证进行条件验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Struts2 可以用于条件验证吗?比如,如果复选框Other"被填写,那么字段otherDetails"不能为空?

Can Struts2 be used for conditional validation? As in, if checkbox "Other" is filled in, then field "otherDetails" must not be empty?

请注意,我正在寻找 Struts2,而不是 Struts1.非常感谢任何示例.

Note that I'm looking for Struts2, not Struts1. Any example is greatly appreciated.

推荐答案

您或许可以使用表达式验证器.如果您通过 XML 进行验证,您应该有如下内容:

You can probably use an expression validator. If you're validating via XML, you should have something like:

<validators>

  <validator type="expression">
    <param name="expression">(other && (otherDetails!=null && otherDetails.trim()!=""))</param>
    <message>You must provide other details.</message>
  </validator>

</validators>

参见 http://struts.apache.org/2.2.1/docs/validation.html 了解更多信息.

See http://struts.apache.org/2.2.1/docs/validation.html for more info.

这篇关于如何使用 Struts2 验证进行条件验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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