[webbeans-commits] Webbeans SVN: r3767 - in extensions/trunk/servlet/int/src/main/java/org/jboss/webbeans/environment/servlet: jsf and 1 other directory.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Wed Sep 23 14:21:14 EDT 2009


Author: pete.muir at jboss.org
Date: 2009-09-23 14:21:14 -0400 (Wed, 23 Sep 2009)
New Revision: 3767

Modified:
   extensions/trunk/servlet/int/src/main/java/org/jboss/webbeans/environment/servlet/Listener.java
   extensions/trunk/servlet/int/src/main/java/org/jboss/webbeans/environment/servlet/jsf/WebBeansApplication.java
Log:
store bean manager in servlet context under better name, don't assume JSP is available

Modified: extensions/trunk/servlet/int/src/main/java/org/jboss/webbeans/environment/servlet/Listener.java
===================================================================
--- extensions/trunk/servlet/int/src/main/java/org/jboss/webbeans/environment/servlet/Listener.java	2009-09-23 18:20:18 UTC (rev 3766)
+++ extensions/trunk/servlet/int/src/main/java/org/jboss/webbeans/environment/servlet/Listener.java	2009-09-23 18:21:14 UTC (rev 3767)
@@ -17,6 +17,7 @@
 package org.jboss.webbeans.environment.servlet;
 
 import javax.el.ELContextListener;
+import javax.enterprise.inject.spi.BeanManager;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.jsp.JspApplicationContext;
 import javax.servlet.jsp.JspFactory;
@@ -133,19 +134,22 @@
       }
 
       // Push the manager into the servlet context so we can access in JSF
-      sce.getServletContext().setAttribute(WebBeansManager.class.getName(), manager);
+      sce.getServletContext().setAttribute(BeanManager.class.getName(), manager);
       
-      JspApplicationContext jspApplicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(sce.getServletContext());
+      if (JspFactory.getDefaultFactory() != null)
+      {
+         JspApplicationContext jspApplicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(sce.getServletContext());
+         
+         // Register the ELResolver with JSP
+         jspApplicationContext.addELResolver(manager.getELResolver());
+         
+         // Register ELContextListener with JSP
+         jspApplicationContext.addELContextListener(Reflections.<ELContextListener>newInstance("org.jboss.webbeans.el.WebBeansELContextListener"));
+         
+         // Push the wrapped expression factory into the servlet context so that Tomcat or Jetty can hook it in using a container code
+         sce.getServletContext().setAttribute(EXPRESSION_FACTORY_NAME, manager.wrapExpressionFactory(jspApplicationContext.getExpressionFactory()));
+      }
       
-      // Register the ELResolver with JSP
-      jspApplicationContext.addELResolver(manager.getELResolver());
-      
-      // Register ELContextListener with JSP
-      jspApplicationContext.addELContextListener(Reflections.<ELContextListener>newInstance("org.jboss.webbeans.el.WebBeansELContextListener"));
-      
-      // Push the wrapped expression factory into the servlet context so that Tomcat or Jetty can hook it in using a container code
-      sce.getServletContext().setAttribute(EXPRESSION_FACTORY_NAME, manager.wrapExpressionFactory(jspApplicationContext.getExpressionFactory()));
-      
       bootstrap.deployBeans().validateBeans().endInitialization();
       super.contextInitialized(sce);
    }

Modified: extensions/trunk/servlet/int/src/main/java/org/jboss/webbeans/environment/servlet/jsf/WebBeansApplication.java
===================================================================
--- extensions/trunk/servlet/int/src/main/java/org/jboss/webbeans/environment/servlet/jsf/WebBeansApplication.java	2009-09-23 18:20:18 UTC (rev 3766)
+++ extensions/trunk/servlet/int/src/main/java/org/jboss/webbeans/environment/servlet/jsf/WebBeansApplication.java	2009-09-23 18:21:14 UTC (rev 3767)
@@ -87,11 +87,11 @@
          throw new IllegalStateException("Not in a servlet environment!");
       }
       ServletContext ctx = (ServletContext) facesContext.getExternalContext().getContext();
-      if (ctx.getAttribute(WebBeansManager.class.getName()) == null)
+      if (ctx.getAttribute(BeanManager.class.getName()) == null)
       {
          throw new IllegalStateException("BeanManager has not been pushed into the ServletContext");
       }
-      return (WebBeansManager) ctx.getAttribute(WebBeansManager.class.getName());
+      return (WebBeansManager) ctx.getAttribute(BeanManager.class.getName());
    }
 
 }




More information about the weld-commits mailing list