To access ServletContext
in an Struts 2 factory class ( For example StrutsTextProviderFactory
)
I used below code:
public class CustomStrutsTextProviderFactory extends
StrutsTextProviderFactory implements ServletContextListener{
private static String myConfig;
@Override
protected TextProvider getTextProvider(Class clazz) {
// I can read myConfig here !
}
@Override
public void contextInitialized(ServletContextEvent event) {
myconfig = event.getServletContext().getInitParameter("config");
}
}
It works but I think define an static
property and setting it in this way is not the best approach.
Is there a better way ?!