This is a hack. What ServletConfig
is, is basically an object containing parameters of a Servlet
. You'll find practically the same methods and info in the ServletRegistration
interface. So it's all the same if you pull the config params off the ServletContext
itself and populate in a custom implementation of ServletConfig
. Try this:
Retrieve the ServletContext
object
FacesContext facesContext = FacesContext.getCurrentInstance();
ServletContext servletContext = (ServletContext) context.getExternalContext(); // Your servlet context here
From the servlet context, get the servlet registration object for the servlet you desire
ServletRegistration reg = servletContext.getServletRegistration("theServlet"); //ServletRegistration contains all the info you'll need to populate a custom ServletConfig object
Use the information you've derived from (2) to populate a custom impl of ServletConfig
ServletConfig myServletConfig = new MyCustomServletConfig();
myServletConfig.setInitParams(reg.getInitParameters()); //do a simple transfer of content
The last step is an oversimplification, but you'll get the idea.
If you were running a previous version of Java EE (pre 3.0), you'll have had access to the ServletContext#getServlet()
which is now deprecated.