How to pass a parameter to a string in properties file
807607Jan 22 2007 — edited Jan 22 2007Hi,
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!