views:

345

answers:

2

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."

A: 

I add depends = "" 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"
 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 = 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

jayjaypg22
A: 

definitive answer :

I needed to use struts tag : html:text etc. to benefit of this mecanism.

Then, I modify the validation rules :

<field property="nom" depends="required">
    <arg0 key="error.nom"/>
</field>

And it works fine!

jayjaypg22