-
1. Re: How to get ServletContext in Web Bean?
meetoblivion Jun 3, 2009 3:35 PM (in response to alin.heyoulin.qq.com)You could provide a @Produces on a servlet that returns the ServletContext
-
2. Re: How to get ServletContext in Web Bean?
alin.heyoulin.qq.com Jun 3, 2009 6:34 PM (in response to alin.heyoulin.qq.com)I modified the class org.jboss.webbeans.environment.servlet.discovery.ServletWebBeanDiscovery add public ServletContext getServletContext() { return servletContext; } then ServletContext servletContext = ((ServletWebBeanDiscovery)CurrentManager.rootManager().getServices().get(WebBeanDiscovery.class)).getServletContext();
-
3. Re: How to get ServletContext in Web Bean?
meetoblivion Jun 3, 2009 7:30 PM (in response to alin.heyoulin.qq.com)While that may work, you're locking yourself into a few scenarios.
1. The only webbeans provider that your application will work with is your own home-grown provider, since this feature's not in the spec. This means that your provider will need to replace the providers in jboss/weblogic/websphere/tomcat/resin/etc. I doubt many people would like that approach.
2. Your provider needs to be built on the jboss provider. it doesn't work against the spec's api's.
-
4. Re: How to get ServletContext in Web Bean?
gavin.king Jun 3, 2009 7:47 PM (in response to alin.heyoulin.qq.com)Right. A much better solution is a producer method or field.
For example:
public class ServletContextBean implements ServletContextListener { @Produces static ServletContext ctx; public void contextInitialized(ServletContextEvent sce) { ctx = sce.getServletContext(); } public void contextDestroyed(ServletContextEvent sce) {} }
Have not tried it on the RI, but according to spec, this should work.
-
5. Re: How to get ServletContext in Web Bean?
pmuir Jun 6, 2009 11:38 PM (in response to alin.heyoulin.qq.com)No this won't work atm, we currently don't regard Servlet objects as 299 contextual objects.
It's on the todo list :-)