Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using more than 1 properties file with Action Form

 
Ritika Saxena
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • 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
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic