Statics should be removed, I agree -- but the situation we are addressing here is the accessibility of the BeanManager in a servlet-environment, as you mentioned previously that we should not rely on JNDI.<br><br>So using a ServletContextListener, BeanManager is in the ServletContext attribute map, then made accessible to the rest of the app via FacesContext.getCurrentInstance() (which is a static call I might add ;)<br>
<br>But statics aside, those 'should' go away, agreed... I have to support Nik here, how would you do it instead?<br><br>--Lincoln<br><br><div class="gmail_quote">On Wed, Apr 14, 2010 at 10:54 AM, Pete Muir <span dir="ltr"><<a href="mailto:pmuir@redhat.com">pmuir@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Guys,<br>
<br>
We cannot rely on statics in Seam 3. Please don't add code like this. If you have a problem accessing the BeanManager from your code, please ask here about the best solution.<br>
<br>
Nik, can you revert this please. And then explain what situation you are trying to address.<br>
<br>
Thanks.<br>
<br>
Begin forwarded message:<br>
<br>
> From: <a href="mailto:seam-commits@lists.jboss.org">seam-commits@lists.jboss.org</a><br>
> Date: 14 April 2010 13:50:21 GMT+01:00<br>
> To: <a href="mailto:seam-commits@lists.jboss.org">seam-commits@lists.jboss.org</a><br>
> Subject: [seam-commits] Seam SVN: r12493 - in modules/faces/trunk/impl/src/main: resources/META-INF/services and 1 other directory.<br>
> Reply-To: <a href="mailto:seam-commits@lists.jboss.org">seam-commits@lists.jboss.org</a><br>
><br>
> Author: nickarls<br>
> Date: 2010-04-14 08:50:21 -0400 (Wed, 14 Apr 2010)<br>
> New Revision: 12493<br>
><br>
> Added:<br>
> modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerPickupExtension.java<br>
> modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/SingletonBeanManagerProvider.java<br>
> Modified:<br>
> modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java<br>
> modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension<br>
> Log:<br>
> Last attempt singletonish approach when others fail. Yes, I'm ashamed.<br>
><br>
> Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java<br>
> ===================================================================<br>
> --- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java 2010-04-14 12:21:26 UTC (rev 12492)<br>
> +++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java 2010-04-14 12:50:21 UTC (rev 12493)<br>
> @@ -45,6 +45,7 @@<br>
> beanManagerProviders.add(ServletContextBeanManagerProvider.DEFAULT);<br>
> beanManagerProviders.add(JndiBeanManagerProvider.DEFAULT);<br>
> beanManagerProviders.add(JndiBeanManagerProvider.JBOSS_HACK);<br>
> + beanManagerProviders.add(SingletonBeanManagerProvider.DEFAULT);<br>
> }<br>
><br>
> protected BeanManager getBeanManager()<br>
><br>
> Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerPickupExtension.java<br>
> ===================================================================<br>
> --- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerPickupExtension.java (rev 0)<br>
> +++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerPickupExtension.java 2010-04-14 12:50:21 UTC (rev 12493)<br>
> @@ -0,0 +1,56 @@<br>
> +/*<br>
> + * JBoss, Home of Professional Open Source<br>
> + * Copyright 2010, Red Hat, Inc., and individual contributors<br>
> + * by the @authors tag. See the copyright.txt in the distribution for a<br>
> + * full listing of individual contributors.<br>
> + *<br>
> + * This is free software; you can redistribute it and/or modify it<br>
> + * under the terms of the GNU Lesser General Public License as<br>
> + * published by the Free Software Foundation; either version 2.1 of<br>
> + * the License, or (at your option) any later version.<br>
> + *<br>
> + * This software is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
> + * Lesser General Public License for more details.<br>
> + *<br>
> + * You should have received a copy of the GNU Lesser General Public<br>
> + * License along with this software; if not, write to the Free<br>
> + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA<br>
> + * 02110-1301 USA, or see the FSF site: <a href="http://www.fsf.org" target="_blank">http://www.fsf.org</a>.<br>
> + */<br>
> +package org.jboss.seam.faces.cdi;<br>
> +<br>
> +import javax.enterprise.event.Observes;<br>
> +import javax.enterprise.inject.spi.AfterBeanDiscovery;<br>
> +import javax.enterprise.inject.spi.BeanManager;<br>
> +import javax.enterprise.inject.spi.Extension;<br>
> +<br>
> +/**<br>
> + * Singleton(ish) extension that observes the AfterBeanDiscovery event and stores the BeanManager for access<br>
> + * in places where injection is not available and JNDI or ServletContext access is not preferable.<br>
> + *<br>
> + * @author Nicklas Karlsson<br>
> + *<br>
> + */<br>
> +public class BeanManagerPickupExtension implements Extension<br>
> +{<br>
> + private static BeanManagerPickupExtension instance;<br>
> + private volatile BeanManager beanManager;<br>
> +<br>
> + public BeanManager getBeanManager()<br>
> + {<br>
> + return beanManager;<br>
> + }<br>
> +<br>
> + public static BeanManagerPickupExtension getInstance()<br>
> + {<br>
> + return instance;<br>
> + }<br>
> +<br>
> + public void pickupBeanManager(@Observes AfterBeanDiscovery e, BeanManager beanManager)<br>
> + {<br>
> + this.beanManager = beanManager;<br>
> + BeanManagerPickupExtension.instance = this;<br>
> + }<br>
> +}<br>
><br>
> Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/SingletonBeanManagerProvider.java<br>
> ===================================================================<br>
> --- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/SingletonBeanManagerProvider.java (rev 0)<br>
> +++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/SingletonBeanManagerProvider.java 2010-04-14 12:50:21 UTC (rev 12493)<br>
> @@ -0,0 +1,43 @@<br>
> +/*<br>
> + * JBoss, Home of Professional Open Source<br>
> + * Copyright 2010, Red Hat, Inc., and individual contributors<br>
> + * by the @authors tag. See the copyright.txt in the distribution for a<br>
> + * full listing of individual contributors.<br>
> + *<br>
> + * This is free software; you can redistribute it and/or modify it<br>
> + * under the terms of the GNU Lesser General Public License as<br>
> + * published by the Free Software Foundation; either version 2.1 of<br>
> + * the License, or (at your option) any later version.<br>
> + *<br>
> + * This software is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
> + * Lesser General Public License for more details.<br>
> + *<br>
> + * You should have received a copy of the GNU Lesser General Public<br>
> + * License along with this software; if not, write to the Free<br>
> + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA<br>
> + * 02110-1301 USA, or see the FSF site: <a href="http://www.fsf.org" target="_blank">http://www.fsf.org</a>.<br>
> + */<br>
> +package org.jboss.seam.faces.cdi;<br>
> +<br>
> +import javax.enterprise.inject.spi.BeanManager;<br>
> +<br>
> +/**<br>
> + * A BeanManager provider for an extension provided singleton<br>
> + *<br>
> + * @author Nicklas Karlsson<br>
> + *<br>
> + */<br>
> +public class SingletonBeanManagerProvider implements BeanManagerProvider<br>
> +{<br>
> +<br>
> + public static final BeanManagerProvider DEFAULT = new SingletonBeanManagerProvider();<br>
> +<br>
> + @Override<br>
> + public BeanManager getBeanManager()<br>
> + {<br>
> + return BeanManagerPickupExtension.getInstance().getBeanManager();<br>
> + }<br>
> +<br>
> +}<br>
><br>
> Modified: modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension<br>
> ===================================================================<br>
> --- modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-04-14 12:21:26 UTC (rev 12492)<br>
> +++ modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-04-14 12:50:21 UTC (rev 12493)<br>
> @@ -1,3 +1,4 @@<br>
> org.jboss.seam.faces.context.ViewScopedExtension<br>
> org.jboss.seam.faces.context.FlashScopedExtension<br>
> -org.jboss.seam.faces.context.FacesAnnotationsAdapterExtension<br>
> \ No newline at end of file<br>
> +org.jboss.seam.faces.context.FacesAnnotationsAdapterExtension<br>
> +org.jboss.seam.faces.cdi.BeanManagerPickupExtension<br>
><br>
> _______________________________________________<br>
> seam-commits mailing list<br>
> <a href="mailto:seam-commits@lists.jboss.org">seam-commits@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/seam-commits" target="_blank">https://lists.jboss.org/mailman/listinfo/seam-commits</a><br>
<br>
<br>
_______________________________________________<br>
seam-dev mailing list<br>
<a href="mailto:seam-dev@lists.jboss.org">seam-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/seam-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/seam-dev</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Lincoln Baxter, III<br><a href="http://ocpsoft.com">http://ocpsoft.com</a><br><a href="http://scrumshark.com">http://scrumshark.com</a><br>"Keep it Simple"<br>