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.
我使用commons-validator v1.2 specification-version:1.0,而struts的spec-version是:1.1。虽然一切正常,但警告框中显示的消息除外。警报框显示案例是相关的。
By instance this jsp field :
通过实例这个jsp字段:
<td class="RechBlocCiel">
<input name="nom" type="text" class="inputForm" size="2" maxlength="50" />
</td>
I put in validation.xml :
我输入了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 :
并在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" />
In xxx.resources.ApplicationResources I have the properties file : ApplicationResources.properties which contains:
在xxx.resources.ApplicationResources中,我有属性文件:ApplicationResources.properties,其中包含:
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."
在我看来,一切都是完整的,所以我不知道现在在哪里搜索,除了验证器和struts之间的版本问题。我正在寻找这样的信息:“Le champ nom est obligatoire。”
2 个解决方案
#1
0
I add depends = "" to
我添加depends =“”
<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"
depends="" msg="errors.required" />
then the error.nom message appears in the alert box. I don't solve the problem completely yet but at least it works with
然后在警告框中显示error.nom消息。我还没有完全解决问题,但至少它可以使用
error.nom = Le champ nom est obligatoire.
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
虽然这个solutino对于我所需的所有表单字段都不是通用的。我没有在通用消息中添加字段名称,而是在我的.properties中重新获得了“Le champ”“est obligatoire”
#2
0
definitive answer :
确定答案:
I needed to use struts tag : html:text etc. to benefit of this mecanism.
我需要使用struts标签:html:text等来受益于这种机制。
Then, I modify the validation rules :
然后,我修改验证规则:
<field property="nom" depends="required">
<arg0 key="error.nom"/>
</field>
And it works fine!
它工作正常!
#1
0
I add depends = "" to
我添加depends =“”
<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"
depends="" msg="errors.required" />
then the error.nom message appears in the alert box. I don't solve the problem completely yet but at least it works with
然后在警告框中显示error.nom消息。我还没有完全解决问题,但至少它可以使用
error.nom = Le champ nom est obligatoire.
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
虽然这个solutino对于我所需的所有表单字段都不是通用的。我没有在通用消息中添加字段名称,而是在我的.properties中重新获得了“Le champ”“est obligatoire”
#2
0
definitive answer :
确定答案:
I needed to use struts tag : html:text etc. to benefit of this mecanism.
我需要使用struts标签:html:text等来受益于这种机制。
Then, I modify the validation rules :
然后,我修改验证规则:
<field property="nom" depends="required">
<arg0 key="error.nom"/>
</field>
And it works fine!
它工作正常!