I have tried to pass dynamic parameters to keyvalue(message to display) which I will get from package.properties to the Action class through the getText() method. To get the message, we can use getText(String keyvalue) method. What should I do to pass some parameters and retrieve the parameters with the message through the getText() method?
I saw some API’s to pass dynamic parameters. But I don’t know how to use, these are the following API’s, click here to see the Struts 2 API Documentation.
getText(String aTextName, List<Object> args)getText(String key, String[] args)getText(String key, String defaultValue, String[] args)
Thanks in advance..
I suppose that you have following properties in your
package.propertiesusername.required=user name is requiredpassword.required=password is requiredyou can use
getText()asNow if we want to use
getText(String key, String[] args)we have to pass following parametersaTextName -the resource bundle key that is to be searched forargs -a list args to be used in a MessageFormat messageThat means the message format pattern and other static strings will, of course, be obtained from resource bundles. Other parameters will be dynamically determined at runtime.
example
we have following entry in resource file
in this
{1}and{0}are the dynamic parameters and will be determined at run time soargswill contain the value of these parameters.So final call will be
getText(disk.data, testArgs);and it will show
Please go through MessageFormat to know how this work