Reputation: 2740
Struts2 Actions normally extend ActionSupport
class which implements of TextProvider
interface and provides access to resource bundle files in a convenient way using getText()
method.
I want to use resource bundle in Interceptors. I guess I have to copy TextProvider
implementation and paste it in my interceptor.
I have already defined global recourse file in struts.xml
<constant name="struts.custom.i18n.resources" value="resources.global" />
And place global.properties
in resources
package.
It works fine in Action Classes
Is there any easier way to use resource bundle in interceptors?
Upvotes: 5
Views: 2902
Reputation: 1415
Your can use the java.util.ResourceBundle
class.
ResourceBundle bundle = ResourceBundle.getBundle("my_resource_name", locale);
bundle.getString("resource_key");
Upvotes: 4
Reputation: 45465
If your action is type of ActionSupport
you can do as:
ActionSupport actionSupport = (ActionSupport)invocation.getAction();
actionSupport.getText("sample.key");
Upvotes: 4