You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Janarthan Sathiamurthy <ja...@yahoo.com> on 2004/03/11 12:15:58 UTC

Struts-Validation and Property file

Hi,
 
I am using Struts validator in my application. I have defined a properties file that has all the error messages for my application. I have mapped this file in my struts-config.xml file.
I have created a new rule specific for my application. I have mapped this in my validation-rules.xml.
Now, in my validation-rules.xml file, i want to specify the 'msg' parameter of the <validator> tag. I want Struts to read this ('msg' parameter value) from the properties file that i have created(the one that contains errors messages with key's mapped to them)
 
Please advice me on how do achieve this ?
 
Regards,
Janarthan S


---------------------------------
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster.

Re: Struts-Validation and Property file

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
So in your validation-rules.xml you have something like...

<validator name="myValidatorRule"
    classname="myPackage.MyValidator"
             method="validateMyRule"
             methodParams="java.lang.Object,
             org.apache.commons.validator.ValidatorAction,
             org.apache.commons.validator.Field,
             org.apache.struts.action.ActionErrors,
             javax.servlet.http.HttpServletRequest"
             depends=""
             msg="errors.myRule">
</validator>

In your properties file you define "errors.myRule"

In your "MyValidator" class you have something like....

     public static boolean validateMyRule(Object bean,

ValidatorAction va,
                                                               ActionErrors
errors,

HttpServletRequest request) {

        boolean invalid = .... /validation check
        if (invalid) {
            errors.add(field.getKey(), Resources.getActionError(request, va,
field));
        }

     }


----- Original Message ----- 
From: "Janarthan Sathiamurthy" <ja...@yahoo.com>
To: <st...@jakarta.apache.org>
Sent: Thursday, March 11, 2004 11:15 AM
Subject: Struts-Validation and Property file


> Hi,
>
> I am using Struts validator in my application. I have defined a properties
file that has all the error messages for my application. I have mapped this
file in my struts-config.xml file.
> I have created a new rule specific for my application. I have mapped this
in my validation-rules.xml.
> Now, in my validation-rules.xml file, i want to specify the 'msg'
parameter of the <validator> tag. I want Struts to read this ('msg'
parameter value) from the properties file that i have created(the one that
contains errors messages with key's mapped to them)
>
> Please advice me on how do achieve this ?
>
> Regards,
> Janarthan S
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Search - Find what you're looking for faster.



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org