You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Felipe Pina <fo...@gmail.com> on 2014/06/11 23:14:42 UTC
BeanManager lookup returing null !
Why beans Set (bold read line ) is empty ?
What is my mistake ?
Could anybody help me ?
*My bean.*
@javax.enterprise.context.RequestScoped
@javax.enterprise.inject.Default
public class Permissao extends NegocioBase<PermissaoDTO> {
....
}
*context.xml*
<Resource name="BeanManager"
auth="Container"
type="javax.enterprise.inject.spi.BeanManager"
factory="org.apache.webbeans.container.ManagerObjectFactory"/>
*web.xml*
<!-- I ran with and without this resource-env-ref section -->
<resource-env-ref>
<description>Object factory for the CDI Bean Manager</description>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
*BeanFactory*
public class BeanFactory {
static BeanManager getBeanManager() {
InitialContext context;
Object result;
try {
context = new InitialContext();
result = context.lookup("java:comp/env/BeanManager"); //lookup in
Tomcat
} catch (NamingException e) {
try {
context = new InitialContext();
result = context.lookup("java:comp/BeanManager"); //lookup in
JBossAS
} catch (NamingException ex) {
throw new RuntimeException("BeanManager could not be found in
JNDI", e);
}
}
return (BeanManager) result;
}
@SuppressWarnings("unchecked")
public static <T> T getContextualInstance(final Class<T> type) {
BeanManager manager = getBeanManager();
T result = null;
*Set<Bean<?>> beans = manager.getBeans(type,
type.getAnnotation(RequestScoped.class));*
*---- > why variable beans isEmpty !!!*
Bean<T> bean = (Bean<T>) manager.resolve(beans);
if (bean != null) {
CreationalContext<T> context =
manager.createCreationalContext(bean);
if (context != null) {
result = (T) manager.getReference(bean, type, context);
}
}
return result;
}
}
--
Atenciosamente,
Felipe Pina
Re: BeanManager lookup returing null !
Posted by Karl Kildén <ka...@gmail.com>.
Felipe,
As a side note I recommend you try Deltaspike core [1] for retrieving
beans. Alternatively you can retrieve with Omnifaces [2] too all though
since Deltaspike is composed by the makers of Weld / OWB that would be my
first bet.
[1] http://deltaspike.apache.org/core.html#beanprovider
[2] http://showcase.omnifaces.org/utils/Beans
On 12 June 2014 09:35, Gerhard Petracek <ge...@gmail.com> wrote:
> hi felipe,
>
> you pass in a scope-annotation as qualifier.
> -> it can't work, since a scope is no qualifier.
>
> (fyi: please ask questions about cdi on the list for openwebbeans.)
>
> regards,
> gerhard
>
> http://www.irian.at
>
> Your JSF/JavaEE powerhouse -
> JavaEE Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>
>
>
> 2014-06-11 23:14 GMT+02:00 Felipe Pina <fo...@gmail.com>:
>
> > Why beans Set (bold read line ) is empty ?
> >
> > What is my mistake ?
> >
> > Could anybody help me ?
> >
> >
> >
> > *My bean.*
> >
> > @javax.enterprise.context.RequestScoped
> > @javax.enterprise.inject.Default
> > public class Permissao extends NegocioBase<PermissaoDTO> {
> > ....
> > }
> >
> >
> > *context.xml*
> > <Resource name="BeanManager"
> > auth="Container"
> > type="javax.enterprise.inject.spi.BeanManager"
> > factory="org.apache.webbeans.container.ManagerObjectFactory"/>
> >
> >
> > *web.xml*
> >
> > <!-- I ran with and without this resource-env-ref section -->
> > <resource-env-ref>
> > <description>Object factory for the CDI Bean Manager</description>
> > <resource-env-ref-name>BeanManager</resource-env-ref-name>
> >
> >
> <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
> > </resource-env-ref>
> >
> > *BeanFactory*
> >
> > public class BeanFactory {
> > static BeanManager getBeanManager() {
> > InitialContext context;
> > Object result;
> > try {
> > context = new InitialContext();
> > result = context.lookup("java:comp/env/BeanManager"); //lookup in
> > Tomcat
> > } catch (NamingException e) {
> > try {
> > context = new InitialContext();
> > result = context.lookup("java:comp/BeanManager"); //lookup in
> > JBossAS
> > } catch (NamingException ex) {
> > throw new RuntimeException("BeanManager could not be found in
> > JNDI", e);
> > }
> > }
> > return (BeanManager) result;
> > }
> > @SuppressWarnings("unchecked")
> > public static <T> T getContextualInstance(final Class<T> type) {
> > BeanManager manager = getBeanManager();
> > T result = null;
> > *Set<Bean<?>> beans = manager.getBeans(type,
> > type.getAnnotation(RequestScoped.class));*
> > *---- > why variable beans isEmpty !!!*
> > Bean<T> bean = (Bean<T>) manager.resolve(beans);
> > if (bean != null) {
> > CreationalContext<T> context =
> > manager.createCreationalContext(bean);
> > if (context != null) {
> > result = (T) manager.getReference(bean, type, context);
> > }
> > }
> > return result;
> > }
> > }
> >
> > --
> > Atenciosamente,
> > Felipe Pina
> >
>
Re: BeanManager lookup returing null !
Posted by Gerhard Petracek <ge...@gmail.com>.
hi felipe,
you pass in a scope-annotation as qualifier.
-> it can't work, since a scope is no qualifier.
(fyi: please ask questions about cdi on the list for openwebbeans.)
regards,
gerhard
http://www.irian.at
Your JSF/JavaEE powerhouse -
JavaEE Consulting, Development and
Courses in English and German
Professional Support for Apache MyFaces
2014-06-11 23:14 GMT+02:00 Felipe Pina <fo...@gmail.com>:
> Why beans Set (bold read line ) is empty ?
>
> What is my mistake ?
>
> Could anybody help me ?
>
>
>
> *My bean.*
>
> @javax.enterprise.context.RequestScoped
> @javax.enterprise.inject.Default
> public class Permissao extends NegocioBase<PermissaoDTO> {
> ....
> }
>
>
> *context.xml*
> <Resource name="BeanManager"
> auth="Container"
> type="javax.enterprise.inject.spi.BeanManager"
> factory="org.apache.webbeans.container.ManagerObjectFactory"/>
>
>
> *web.xml*
>
> <!-- I ran with and without this resource-env-ref section -->
> <resource-env-ref>
> <description>Object factory for the CDI Bean Manager</description>
> <resource-env-ref-name>BeanManager</resource-env-ref-name>
>
> <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
> </resource-env-ref>
>
> *BeanFactory*
>
> public class BeanFactory {
> static BeanManager getBeanManager() {
> InitialContext context;
> Object result;
> try {
> context = new InitialContext();
> result = context.lookup("java:comp/env/BeanManager"); //lookup in
> Tomcat
> } catch (NamingException e) {
> try {
> context = new InitialContext();
> result = context.lookup("java:comp/BeanManager"); //lookup in
> JBossAS
> } catch (NamingException ex) {
> throw new RuntimeException("BeanManager could not be found in
> JNDI", e);
> }
> }
> return (BeanManager) result;
> }
> @SuppressWarnings("unchecked")
> public static <T> T getContextualInstance(final Class<T> type) {
> BeanManager manager = getBeanManager();
> T result = null;
> *Set<Bean<?>> beans = manager.getBeans(type,
> type.getAnnotation(RequestScoped.class));*
> *---- > why variable beans isEmpty !!!*
> Bean<T> bean = (Bean<T>) manager.resolve(beans);
> if (bean != null) {
> CreationalContext<T> context =
> manager.createCreationalContext(bean);
> if (context != null) {
> result = (T) manager.getReference(bean, type, context);
> }
> }
> return result;
> }
> }
>
> --
> Atenciosamente,
> Felipe Pina
>