-
1. Re: Programatically activating an Alternative...
nickarls Dec 19, 2009 11:06 AM (in response to matt.corey)Write extension. Cast to impl. Get hold of BDA. Parse faces-cfg. Add beans.xml. Posted from mobile :-)
-
2. Re: Programatically activating an Alternative...
nickarls Dec 20, 2009 10:30 AM (in response to matt.corey)I wouldn't mind having an event for each deployment archive that would have enableAlternative(Class<?>) and same for interceptors and decorators...
-
3. Re: Programatically activating an Alternative...
matt.corey Dec 22, 2009 5:59 AM (in response to matt.corey)Holy cow -- translation needed, please! :) What object am I casting into what other object? What's a BDA, and what do I do with it?
If there were an 'enableAlternative' method, as you say, I would have figured it out by now, but I didn't find one :)
M
-
4. Re: Programatically activating an Alternative...
nickarls Dec 22, 2009 7:59 AM (in response to matt.corey)Write an extension (see the refdoc) that listens to the
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd) { }
in Weld, this will be a AfterBeanDiscoveryImpl so you can cast to that. Use reflection to access the private beanDeployments and then use BeanDeploymentArchive.getBeansXml().add(my_own_beans_xml_with_correct_stereotype_enabled). The beans.xml will be merged to enable the correct stereotype.
Now, I don't think JSF has booted at this point so you don't have a FacesContext to work on (and can't mock one since the impl. itself is not there year) so you are better off getting the faces-config.xml yourself and parsing the production/devel mode from there.
This is so ugly, I'm not sure why I'm even telling you this ;-)
PS. Not tested, just looking at the code...
-
5. Re: Programatically activating an Alternative...
matt.corey Dec 22, 2009 1:29 PM (in response to matt.corey)Ah, gotcha -- so it's basically a not-quite-portable extension... that's a bit disappointing, but potentially something I could work with...
And you're right, it's definitely ugly to manually parse the faces-config.xml... must be some other hook I can look for :)
Thanks,
M -
6. Re: Programatically activating an Alternative...
nickarls Dec 22, 2009 1:42 PM (in response to matt.corey)Well, I'm sure you might be able to bootstrap JSF yourself with mock objects and the faces-config.xml location (check out ConfigureListener() in JSF 2) but it might be a bit heavy...
-
7. Re: Programatically activating an Alternative...
matt.corey Dec 23, 2009 6:40 AM (in response to matt.corey)Nicklas -- is this something that should work in Glassfish's CDI runtime (which uses Weld, as I'm sure you know)? When I try to cast to AfterBeanDiscoveryImpl, I get a ClassNotFoundException, even if I include the weld-spi.jar in my webapp...
M
-
8. Re: Programatically activating an Alternative...
matt.corey Dec 23, 2009 6:43 AM (in response to matt.corey)Hmm, got around the ClassNotFoundException when I realized that the AfterBeanDiscoveryImpl is in the weld-core jar file, but now I get
java.lang.ClassCastException: org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl cannot be cast to org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl
Usually this indicates a ClassLoader issue -- I'm presuming at this point that the Glassfish version is either a different version, or a slight variation...
M
-
9. Re: Programatically activating an Alternative...
nickarls Dec 23, 2009 7:17 AM (in response to matt.corey)Don't include any weld-specific jar:s in your webapp
-
10. Re: Programatically activating an Alternative...
gavin.king Dec 27, 2009 5:33 AM (in response to matt.corey)In the next rev of CDI, I want to add a Module interface and a ProcessModule event to let you mess with enabled alternatives, interceptors, decorators. For now there's no good portable way to mess with the module-level metadata.
This is a major item on the portable extension SPI wishlist.
-
11. Re: Programatically activating an Alternative...
matt.corey Dec 29, 2009 4:59 AM (in response to matt.corey)Sounds good, Gavin -- is that something that's in the works, or are we going to have to wait a few years for JEE 7?
M
-
12. Re: Programatically activating an Alternative...
gavin.king Dec 29, 2009 7:20 AM (in response to matt.corey)
Matt Corey wrote on Dec 29, 2009 04:59:
Sounds good, Gavin -- is that something that's in the works, or are we going to have to wait a few years for JEE 7?No, we plan a CDI 1.1 release way before EE 7.