-
1. Re: Integrating DWR and Weld: @Named implicitly: How to get the name?
swd847 Nov 22, 2009 6:13 AM (in response to luxspes)I think that would be a definition error, but I am not sure. Don't forget that if a stereotype is annotated @Named then the bean is implicitly named as well.
-
2. Re: Integrating DWR and Weld: @Named implicitly: How to get the name?
swd847 Nov 22, 2009 6:17 AM (in response to luxspes)Can you do:
Set<Bean<?>> beans = manager.getBeans(Object.class, new DwrBeanLiteral()); for(Bean b : beans) { String name = b.getName(); }
where DwrBeanLiteral is
public class DwrBeanLiteral extends AnnotationLiteral<DwrBean> implements DwrBean {};
and the manager is looked up from JNDI?
-
3. Re: Integrating DWR and Weld: @Named implicitly: How to get the name?
luxspes Nov 22, 2009 6:22 AM (in response to luxspes)Yeap, I was starting to think that using manager.getBeans would be much less complicated... I guess I got confused because in Spring something like manager.getBeans would return actual bean instances... but apparently in Weld that returns beans definitions (to create bean instances I should instead use createInjectionTarget.
Guess I got confused...
Thanks a lot! -
4. Re: Integrating DWR and Weld: @Named implicitly: How to get the name?
luxspes Nov 22, 2009 6:31 AM (in response to luxspes)I am still confused... now... if manager.getBeans(nameInString) gets me all the bean definitions for that name... how do I get a bean instance from that bean definition?
-
5. Re: Integrating DWR and Weld: @Named implicitly: How to get the name?
swd847 Nov 22, 2009 6:48 AM (in response to luxspes)Try this:
CreationalContext cc = manager.createCreationalContext(bean); Object beanInstance = manager.getReference(bean, type, cc);
Bean is the Bean object and type is the Java class of the Bean. I'm not sure if this is the official way of doing it.
-
6. Re: Integrating DWR and Weld: @Named implicitly: How to get the name?
gavin.king Nov 22, 2009 7:22 AM (in response to luxspes)To get all beans, you can use BeanManager.getBeans(Object.class, new AnnotationLiteral<Any>(){}).
To get all beans with a @Named annotation, you can use BeanManager.getBeans(Object.class, new AnnotationLiteral<Named>(){}), since @Named is a qualifier.
:-)
-
7. Re: Integrating DWR and Weld: @Named implicitly: How to get the name?
gavin.king Nov 22, 2009 7:26 AM (in response to luxspes)
Stuart Douglas wrote on Nov 22, 2009 06:48:
Try this:CreationalContext cc = manager.createCreationalContext(bean); Object beanInstance = manager.getReference(bean, type, cc);
Bean is the Bean object and type is the Java class of the Bean. I'm not sure if this is the official way of doing it.Yes, that's correct.
-
8. Re: Integrating DWR and Weld: @Named implicitly: How to get the name?
luxspes Nov 22, 2009 8:44 AM (in response to luxspes)Thanks to Stuart! Thanks to Gavin! Weld is great!
-
9. Re: Integrating DWR and Weld: @Named implicitly: How to get the name?
luxspes Nov 22, 2009 8:48 AM (in response to luxspes)My code looks like this:
Bean<?> beanDefinition = getBeanDefinition(id); CreationalContext cc = beanFactory.createCreationalContext(beanDefinition); Object beanInstance = beanFactory.getReference(beanDefinition, beanDefinition.getBeanClass(), cc);
I just wonder... why I can not just do this:
Bean<?> beanDefinition = getBeanDefinition(id); CreationalContext cc = beanFactory.createCreationalContext(beanDefinition); Object beanInstance = beanFactory.getReference(beanDefinition, cc);
After all the beanDefinition knows the beanClass... why getReference needs 2 parameters?
-
10. Re: Integrating DWR and Weld: @Named implicitly: How to get the name?
swd847 Nov 22, 2009 9:59 AM (in response to luxspes)I thinks its for session beans where you can have 2 distict local interfaces, and no bean class, so you need to pick which interface you want.
-
11. Re: Integrating DWR and Weld: @Named implicitly: How to get the name?
gavin.king Nov 22, 2009 4:34 PM (in response to luxspes)
Stuart Douglas wrote on Nov 22, 2009 09:59:
I thinks its for session beans where you can have 2 distict local interfaces, and no bean class, so you need to pick which interface you want.Also for managed beans where the bean class is unproxyable, but has some other bean type that is proxyable.
There can even be some more exotic cases with custom beans.