Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to pass a parameter to a string in properties file

807607Jan 22 2007 — edited Jan 22 2007
Hi,

I have a properties file (text file) which has a list of some error messages which are displayed to the user.

Here are the three sample strings I have in the properties file:
field.name=User-name
error.invalid=Some of the values entered are invalid.
field.invalid={0} is invalid.

Now, if a user enters an invalid User-name, then back in the action class I have a line of code in this format (inside an if-then block):

errors.add("user", new ActionError("error.invalid"));

This looks for the relevant string in the properties file for "error.invalid" and displays to the user "Some of the values entered are invalid."

However, this does not tell the user the exact field where the problem is. I have a different string in the properties file: field.invalid={0} is invalid. And the other one is: field.name=User-name.

Is there a way I can pass the 'field.name' as a parameter to the string 'field.invalid' for the {0}? If this is possible, the user will see: "User-name is invalid."

In theory, the {0} was replaced with parameter I passed. But I am having problem with the sytax of this. The following is what I have that works without passing any parameters:

errors.add("user", new ActionError("error.invalid"));

Any guidance will be helpful. Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 19 2007
Added on Jan 22 2007
8 comments
1,325 views