File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts validation - messages from custom Resource bundle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts validation - messages from custom Resource bundle" Watch "Struts validation - messages from custom Resource bundle" New topic

Struts validation - messages from custom Resource bundle

Pious Francis

Joined: Jun 25, 2004
Posts: 11
Hi All,
I'm using struts 1.1 validation frame work with Websphere 5. The follwing tag is configured in the validation.xml file.
<form name="loginForm">
<field property="employee_id" depends="required">
<arg0 name="required" key="loginform.employee_id"/>
I am using different resource bundles. I want the validator to take 'loginform.employee_id' key from my custom Resource Bundle,say, which is in the /AppServer/resources directory which is also in the classpath.
I've given the entries :
errors.required={0} is required.
loginform.employee_id=Employee Id
in the custom resource bundle.

But the validator takes only the value of 'errors.required' and not of 'loginform.employee_id' from the property file and the error message is
' required'. If I'm giving 'loginform.employee_id' in the then the right message "Employee Id is required" will come.

Does it mean that the key 'loginform.employee_id' should be taken only from the

How can I make the validator to read the key from my custom resource bundle?

Thanks in Advance
John Boot

Joined: Jul 22, 2004
Posts: 12
My guess is

null="false" /> in struts-config.xml

i.e. will be used
Pious Francis

Joined: Jun 25, 2004
Posts: 11
I've already done this in struts-config.xml. But still the validator ignores the custom bundle.

Karl Beowulph
Ranch Hand

Joined: May 31, 2004
Posts: 130
I don't think you can use custom bundles for auto-validation.

I was trying for about a week with no luck.
John Carnell
Ranch Hand

Joined: Sep 27, 2002
Posts: 71
Hi Pious,

Sorry I cant be much help here. I have never tried to use the validator with a custom resource property file. If I get time tonight I will try to look through the source.

The one thing you need to be aware of with the Validator and Tiles pieces of Struts is that they are really plug-ins to the core Struts framework. This means things do not always work the way you expect them to when using them. Your best bet is to open the source for the Validator plugin (org.apache.struts.validator.ValidatorPlug) and see if allows you to access a resource bundle independent of what you have configured for Struts.


P.S. Like I said if I get some time I will whip open the source and see if I can find an answer.

John Carnell<br />Principal Architect<br /> <br />Netchange, LLC<br />1161 HillCrest Heights<br />Green Bay, WI 54313<br /> <br /><br /> <br /> <br />Author of <a href="" target="_blank" rel="nofollow">Pro Jakarta Struts, Second Edition</a>
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
I never use key in custom language but i'm use only key in english language.

It's different in detail .


Java Developer, Thailand
Mathivanan Pandurangan

Joined: Jun 09, 2004
Posts: 6

hi Pious Francis,
I hav'nt used multiple properties file..
but i have used my custom resource property file and it works fine.
the problem.
Earlier, i had the problem of internationalization when the same file was named as

the entry i made in struts-config.xml was
<message-resources parameter="resources.EmpAppResource" />

i hope will be a little help to you.


Nicola Guy
Ranch Hand

Joined: Jun 23, 2004
Posts: 91
I'm new to this and not 100% sure if this would work but could you go to the validation-rules.xml and change the msg for the 'required' rule to your custom message and have the key so that the field name will be inserted!
Pious Francis

Joined: Jun 25, 2004
Posts: 11
Thanks All
Infact suggestion from Nicola Guy will work if i say resource=false and message as the key in validation.xml. Then there is no use from the custom bundle.

and it's known that Struts 1.2 solves this problem with a new 'bundle' attribue in the validation.xml.

Any ideas....

I agree. Here's the link:
subject: Struts validation - messages from custom Resource bundle
It's not a secret anymore!