Please consult XWork's validation framework documentation for complete details
这个地址连接到http://wiki.opensymphony.com/display/XW/Standard+Validators
,这里描述了一些复杂验证器的应用方法。其中我看到了以下内容:
(注:粗黑体字是要验证的表单控件名称)
-----------------------------------------------------------------------------
第一种方法:
ExpressionValidator
This validator uses an OGNL expression to perform its validation. The error message will be added to the action if the expression returns false when it is evaluated against the value stack.
Parameter Required Default Notes
expression yes An OGNL expression that returns a boolean value.
Example:
foo > bar
-------------------------------------------------------------------------------
第二种方法:
FieldExpressionValidator
This validator uses an OGNL expression to perform its validation. The error message will be added to the field if the expression returns false when it is evaluated against the value stack.
Parameter Required Default Notes
expression yes An OGNL expression that returns a boolean value.
Example:
homepage.indexOf('opensymphony.com') == -1
-------------------------------------------------------------------------------
使用第二种验证方法可以将验证的内容写在所在的表单元素的field标签中,哈哈,这个很好,以后也方便改写。(第一种方法也行,但要分开写!看着不爽阿!)
这东东用的是OGNL语法写表达式的,可以看 http://www.ognl.org/ 参考它的写法。
以下的网址讨论了一些写表达式时常出现的问题:
http://wiki.opensymphony.com/display/XW/ExpressionValidator+Tips