Reputation: 31
I just want to know if there's a way to access the properties from a utility class used by an Action class. To access the properties from an Action class we extend the ActionSupport and use the getText("property.key.name")
method.
So, my question is -should every other class extend the ActionSupport to access properties, even though its not an Action class? or is there any other way?
Thanks
Upvotes: 0
Views: 945
Reputation: 160191
I wouldn't extend ActionSupport
unless you're actually defining an action.
The S2/XW2 ActionSupport
class uses com.opensymphony.xwork2.DefaultTextProvider
; you might be able to use it in your own classes. I'm a little wary of this since I'm not convinced non-action classes should be accessing the web-app's resources, but I haven't given it much thought, so it could be valid. I also haven't tried to do it.
Upvotes: 1
Reputation: 1125
//I wanna make you understand how struts doing it.
public class ActionSupport implements Action, Validateable, ValidationAware, TextProvider, LocaleProvider, Serializable {
//Action support implementation.
//Here TextProvider takes care about resource bundle thing.
}
Upvotes: 0
Reputation: 23587
ActionSuport
is kind of helper class being developed by S2 developers to supplement the Development as it provides many features OOTB.
getText()
is one of the use-case where S2 provides a way to read the property files.This method is specific to S2 as it know how to transverse the hierarchy to read the property files and in what order.
There are many ways to read the property files in a application and few of them are
if you are using Spring, it has a very handy mechanism to read property files - how-to-read-properties-file-in-spring
Apache Common also provides a way to read the file
In short to read properties file there are many ways, S2 getText()
is a way developed by the S2 to read the property file with respect to your actions.
Upvotes: 0