Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Struts validation - messages from custom Resource bundle

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"/>
</field>
</form>
I am using different resource bundles. I want the validator to take 'loginform.employee_id' key from my custom Resource Bundle,say myAppMessages.properties, 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 ApplicationResource.properties 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 AppicationResources.properties.

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

Thanks in Advance
Pious
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is

<message-resources
parameter="net/reumann/conf/blaaResources"
null="false" /> in struts-config.xml


i.e. blaaResources.properties will be used
 
Pious Francis
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've already done this in struts-config.xml. But still the validator ignores the custom bundle.

Pious
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can use custom bundles for auto-validation.

I was trying for about a week with no luck.
 
Author
Posts: 93
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks,
John

P.S. Like I said if I get some time I will whip open the source and see if I can find an answer.
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never use key in custom language but i'm use only key in english language.

It's different in detail .

Example
MessageResources.properties



MessageResources_th.properties

 
Greenhorn
Posts: 6
Oracle Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Pious Francis,
I hav'nt used multiple properties file..
but i have used my custom resource property file EmpAppResource_en_US.properties and it works fine.
the problem.
Earlier, i had the problem of internationalization when the same file was named as EmpAppResource.properties.

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

i hope will be a little help to you.

regards
mathi
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....

Thanks
Pious
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic