You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Ben Avery <be...@youthnetuk.org> on 2005/04/20 18:54:13 UTC
[validator] Resource bundle with standalone validation
I want to use a resource bundle to generate meaningful error messages,
using Validator in a standalone, non-Struts environment.
What do I need to put in the Java class which instantiates and calls the
Validator, so it understands which resourcebundle file to look up
references like
xml config file:
...
<global>
<validator
name="email"
classname="org.youthnet.ben.ValidatorWrapper"
method="doValidEmail"
methodParams="java.lang.Object, org.apache.commons.validator.Field"
msg="errors.email"/>
...
</global>
<formset>
<form name="simpleform">
<field property="startDate" depends="required">
<arg position="0" key="Start date"/>
</field>
...
</form>
</formset>
...
the resource file would look like:
errors.required={0} is required.
errors.maxlength={0} cannot be greater than {1} characters.
errors.email={0} is an invalid email address.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [validator] Resource bundle with standalone validation
Posted by Matt Goodwin <mg...@metalexis.com>.
There is a good discussion of that on the Commons-Validator site. If
you're in a web environment you basically initilalize your resource
bundle in an initialization servlet. Check out this link.
http://wiki.apache.org/jakarta-commons/ValidatorStandalone. If you need
an example of the code I can send you what I've done. If you're outside
the web environment there are a few other things that you can do, but I
will let others speak on that as I have not done that.
Thanks,
Matt
Ben Avery wrote:
> I want to use a resource bundle to generate meaningful error messages,
> using Validator in a standalone, non-Struts environment.
>
> What do I need to put in the Java class which instantiates and calls
> the Validator, so it understands which resourcebundle file to look up
> references like
>
> xml config file:
> ...
> <global>
> <validator
> name="email"
> classname="org.youthnet.ben.ValidatorWrapper"
> method="doValidEmail"
> methodParams="java.lang.Object, org.apache.commons.validator.Field"
> msg="errors.email"/>
> ...
> </global>
>
> <formset>
> <form name="simpleform">
> <field property="startDate" depends="required">
> <arg position="0" key="Start date"/>
> </field>
> ...
> </form>
> </formset>
> ...
>
> the resource file would look like:
>
> errors.required={0} is required.
> errors.maxlength={0} cannot be greater than {1} characters.
> errors.email={0} is an invalid email address.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
--
Matt Goodwin
mgoodwin@metalexis.com
(515)708-0114
Metalexis
"Transcending the Ordinary"
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org