struts验证器客户端,警报框没有消息
我使用 commons-validator v1.2 规范版本:1.0,而我的 struts 规范版本是:1.1。尽管除了警报框中显示的消息之外一切正常。警报框展示案例是相关的。
例如这个jsp字段:
<td class="RechBlocCiel">
<input name="nom" type="text" class="inputForm" size="2" maxlength="50" />
</td>
我放入validation.xml:
<field property="nom" depends="required">
<msg name="required" key="error.nom" />
</field>
与struts配置相关
<validator name="required"
classname="org.apache.struts.validator.FieldChecks"
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
msg="errors.required" />
并在struts配置中声明插件:
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
<message-resources
parameter="xxx.resources.ApplicationResources" />
在xxx.resources.ApplicationResources中,我有属性文件:ApplicationResources.properties,其中包含:
errors.required = <li> Le champ [{0}] est obligatoire.</li>
error.nom = nom
在我看来,一切都已完成,所以我不知道现在在哪里搜索,除了验证器和struts之间的版本问题。 我正在寻找这样的信息:“Le champ nom est obligatoire”。
I use commons-validator v1.2 specification-version : 1.0 whereas my spec-version for struts is : 1.1. Although everything works fine except the message display in the alert box. The alert box display case are relevant.
By instance this jsp field :
<td class="RechBlocCiel">
<input name="nom" type="text" class="inputForm" size="2" maxlength="50" />
</td>
I put in validation.xml :
<field property="nom" depends="required">
<msg name="required" key="error.nom" />
</field>
related to
<validator name="required"
classname="org.apache.struts.validator.FieldChecks"
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
msg="errors.required" />
and in struts config the plugin is declared :
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
<message-resources
parameter="xxx.resources.ApplicationResources" />
In xxx.resources.ApplicationResources I have the properties file : ApplicationResources.properties which contains:
errors.required = <li> Le champ [{0}] est obligatoire.</li>
error.nom = nom
It seems to me that everything is complete, so I'm not sure where to search now, except in a problem of version between validator and struts.
I 'm looking for the message : "Le champ nom est obligatoire."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我添加 dependent = "" 然后
error.nom 消息出现在警报框中。我还没有完全解决问题,但至少它适用于
虽然这个解决方案对于我所需的所有表单字段来说并不通用。我没有将字段名称添加到通用消息中,而是在 .properties 中重新添加了“Le champ”“est obligatoire”
I add depends = "" to
then the error.nom message appears in the alert box. I don't solve the problem completely yet but at least it works with
Though this solutino isn't generic for all my form fields required. Instead of adding the field name to the generic message I have redondance of "Le champ" "est obligatoire" in my .properties
明确的答案:
我需要使用 struts 标签:html:text 等来受益于这种机制。
然后,我修改了验证规则:
并且效果很好!
definitive answer :
I needed to use struts tag : html:text etc. to benefit of this mecanism.
Then, I modify the validation rules :
And it works fine!