使用 Struts 2 进行表单验证 + Dojo框架
我是 Dojo 的新手,我正在尝试验证表单(如本示例的最后一个表单:http://dojotoolkit.org/documentation/tutorials/1.6/validation/),使用Struts2标签,但我不能。 使用“经典”HTML 表单(标签,...)一切都很好,但是使用 Struts 2 标签(),“必需”验证不起作用...
这是我的代码:
<script type="text/javascript">
dojo.require('dojox.validate');
dojo.require('dojox.validate.us');
dojo.require('dojox.validate.web');
/* basic dijit classes */
dojo.require('dijit.form.CheckBox');
dojo.require('dijit.form.Textarea');
dojo.require('dijit.form.FilteringSelect');
dojo.require('dijit.form.TextBox');
dojo.require('dijit.form.ValidationTextBox');
dojo.require('dijit.form.DateTextBox');
dojo.require('dijit.form.TimeTextBox');
dojo.require('dijit.form.Button');
dojo.require('dijit.form.RadioButton');
dojo.require('dijit.form.Form');
dojo.require('dijit.form.DateTextBox');
/* basic dojox classes */
dojo.require('dojox.form.BusyButton');
dojo.require('dojox.form.CheckedMultiSelect');
</script>
<s:form dojoType="dijit.form.Form" method="post" id="toto"
theme="simple">
<script type="dojo/method" event="onSubmit">
if(this.validate()) {
return confirm('Form is valid, press OK to submit');
} else {
alert('Formulaire invalide');
return false;
}
return true;
</script>
<table cellpadding="0" cellspacing="2">
<tr>
<td valign="top"><strong>First Name*: </strong></td>
<td>
<s:textfield
name="email"
id="email"
placeholder="Your email"
dojoType="dijit.form.ValidationTextBox"
required="true"
missingMessage="Obligatoire !" />
</td>
</tr>
</table>
<s:submit
value="Submit Form"
label="Submit Form"
id="submitButton"
dojoType="dijit.form.Button"/>
</s:form>
我如何检查我的字段不为空,带有 struts 标签吗? 谢谢大家
I'm new on Dojo, and I'm trying to validate a form (like the last one of this example : http://dojotoolkit.org/documentation/tutorials/1.6/validation/), using Struts2 tags, but I can't.
With a "classic" HTML form (tags , ....) everything is fine, but with Struts 2 tags (), the "required" validation don't work ...
Here is my code :
<script type="text/javascript">
dojo.require('dojox.validate');
dojo.require('dojox.validate.us');
dojo.require('dojox.validate.web');
/* basic dijit classes */
dojo.require('dijit.form.CheckBox');
dojo.require('dijit.form.Textarea');
dojo.require('dijit.form.FilteringSelect');
dojo.require('dijit.form.TextBox');
dojo.require('dijit.form.ValidationTextBox');
dojo.require('dijit.form.DateTextBox');
dojo.require('dijit.form.TimeTextBox');
dojo.require('dijit.form.Button');
dojo.require('dijit.form.RadioButton');
dojo.require('dijit.form.Form');
dojo.require('dijit.form.DateTextBox');
/* basic dojox classes */
dojo.require('dojox.form.BusyButton');
dojo.require('dojox.form.CheckedMultiSelect');
</script>
<s:form dojoType="dijit.form.Form" method="post" id="toto"
theme="simple">
<script type="dojo/method" event="onSubmit">
if(this.validate()) {
return confirm('Form is valid, press OK to submit');
} else {
alert('Formulaire invalide');
return false;
}
return true;
</script>
<table cellpadding="0" cellspacing="2">
<tr>
<td valign="top"><strong>First Name*: </strong></td>
<td>
<s:textfield
name="email"
id="email"
placeholder="Your email"
dojoType="dijit.form.ValidationTextBox"
required="true"
missingMessage="Obligatoire !" />
</td>
</tr>
</table>
<s:submit
value="Submit Form"
label="Submit Form"
id="submitButton"
dojoType="dijit.form.Button"/>
</s:form>
How can I check that my fields are not empty with struts tags please ?
Thank you all
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要检查以确保您所渲染的内容是 Dojo 所期望的。我不知道当前的 Dojo 验证是如何工作的,但是:
“required”属性是
的一个属性,它可能不会被渲染,因此对 Dojo 不可用 - Dojo 使用它来确定某个字段是否为必填字段。You need to check to make sure that what you're rendering is what Dojo expects. I don't know how the current Dojo validation works, but:
The "required" attribute is an attribute of
<s:textfield>
, it's likely not being rendered, thus not available to Dojo--if that's what Dojo uses to determine if a field is required.