Struts 2 验证 - Do 表达式 &字段表达式验证器支持自动渲染 OGNL 表达式的客户端吗?
Struts 2 表达式
和/或 fieldexpression
验证器是否支持自动渲染验证 XML 文件中定义的 OGNL 表达式的客户端 ECMAScript/JavaScript 验证,就像为验证所做的那样其他捆绑验证器(requiredstring< /code>、
字符串长度
等)?
我问,因为以下 ECMAScript 是为客户端呈现的此表单,并且我在任何地方都看不到我的 OGNL 表达式。我已经尝试过 expression
和 fieldexpression
验证器,它们都呈现以下内容:
function validateForm_dlgIdSearch_form() {
form = document.getElementById("dlgIdSearch_form");
clearErrorMessages(form);
clearErrorLabels(form);
var errors = false;
var continueValidation = true;
// field name: searchFilter.number
// validator name: fieldexpression
if (form.elements['searchFilter.number']) {
field = form.elements['searchFilter.number'];
var error = "Employee number is required.";
}
return !errors;
}
我试图要求至少三个搜索字段之一,并且我不确定是否我犯了一个错误,或者 Struts 2 的验证不支持 expression
和 fieldexpression
验证器的自动客户端 ECMAScript 生成。
Do the Struts 2 expression
and/or fieldexpression
validators support automatically rendering client-side ECMAScript/JavaScript validation for the OGNL expression defined in the validation XML file, like what is done for the other bundled validators (requiredstring
, stringlength
, etc.)?
I ask, because the following ECMAScript is rendered for client-side for this form, and I don't see my OGNL expression anywhere. I've tried the expression
and fieldexpression
validators and they both render this:
function validateForm_dlgIdSearch_form() {
form = document.getElementById("dlgIdSearch_form");
clearErrorMessages(form);
clearErrorLabels(form);
var errors = false;
var continueValidation = true;
// field name: searchFilter.number
// validator name: fieldexpression
if (form.elements['searchFilter.number']) {
field = form.elements['searchFilter.number'];
var error = "Employee number is required.";
}
return !errors;
}
I am trying to require at least one of three search fields, and I'm not sure if I've made a mistake or if Struts 2's validation doesn't support automatic client-side ECMAScript generation for expression
and fieldexpression
validators.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过多次测试,我确信
expression
和fieldexpression
验证器不会呈现客户端 JavaScript 验证。After much testing, I'm convinced that
expression
andfieldexpression
validators do not render client-side JavaScript validation.