简体   繁体   中英

How to tell JSF 2.0 in Glassfish to instantiate an CDI @Alternative to a <managed-bean>?

We have a JSF 2.0 application running under Glassfish 3.1.1 which has been moved forward from JSF 1. This mean that I have a faces-config.xml saying

<managed-bean>
    <managed-bean-name>OnlineBeanHandler</managed-bean-name>
    <managed-bean-class>X.jsf.OnlineBeanHandler</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
            ...
</managed-bean>

which was done to allow using #{OnlineBeanHandler} in my facelet pages. Works well. I can also use @javax.inject.Inject inside OnlineBeanHandler to get a CDI managed bean which I can then provide an alternative for by marking it @javax.enterprise.inject.Alternative and enabling it in beans.xml. Works well.

Now I need to have the same mechanism working for OnlineBeanHandler itself - ie have the <managed-bean> -handling code invoke my alternative class instead of the one explicitly named, but when following the same steps, I still get my base class instead of my alternative.

Can this be done directly and if so how?


Apparently this mechanism does not work there. In the current situation, we could do with creating yet another faces-config.xml file and just have those to be overridden by projects there. A replacement faces-config.xml is then provided by each project.

Those two types of manages beans are exclusive. CDI Alternatives only work for CDI managed beans, not JSF manages beans. You could remove the XML snippet in faces-config and add @Named then you will be able to use @Alternative.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM