This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Using more than 1 properties file with Action Form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Using more than 1 properties file with Action Form" Watch "Using more than 1 properties file with Action Form" New topic
Author

Using more than 1 properties file with Action Form

Ritika Saxena
Ranch Hand

Joined: Jul 02, 2006
Posts: 51
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

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Ritika Saxena
Ranch Hand

Joined: Jul 02, 2006
Posts: 51
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

Joined: Feb 15, 2005
Posts: 4864
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using more than 1 properties file with Action Form
 
Similar Threads
ValidatorForm exception in struts framework
validate method with resource file reference?
Advice for Struts forms with validation
ActionError problem in Struts 2.0
Error with validation