• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using more than 1 properties file with Action Form

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am developing a Struts application with two properties file(ApplicationResources.properties and ErrorMessages.properties). Now I am validating form data through ActionForm's validate method as:

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if(id == null || id == "" || id.length() == 0) {
errors.add("userid", new ActionError("login.userid.error"));
}
if(password == null || password == "" || password.length() == 0) {
errors.add("password", new ActionError("login.password.error"));
}
return errors;
}

If there is only one properties file i.e ApplicationResources.properties; the application is working fine. But if I distribute the key-value pairs in two files, it gives an exception.

How can I solve this problem?

Thanks,
Ruchi
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you display the error messages in your JSP using either the <html:errors /> or <html:messages> tag, you can specify which resource bundle to use with the bundle attribute. If you don't specify a bundle, Struts will use the default bundle.
 
Ritika Saxena
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill, thanks for your reply.

I can very well use more than one resource bundles in jsp using the way you mentioned. But is there any way by which I can let my action form know as to which resource bundle is used for this form.

Thanks,
Ruchi
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ritika Saxena:
But is there any way by which I can let my action form know as to which resource bundle is used for this form.


No, there isn't. An ActionMessage does not contain information about which bundle will be used. All it has is a message key. If you wanted to, you could use one bundle for displaying it under one circumstance, and another for another circumstance.

As long as the JSP uses the correct bundle when displaying the error message, why does the ActionForm need to know which bundle is going to be used?
[ May 10, 2007: Message edited by: Merrill Higginson ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic