Can CDI managed beans and JSF managed beans talk to each other?

女生的网名这么多〃 提交于 2019-11-30 14:49:56
jan groth

All JSF managed beans (JMB) either are CDI managed beans (CMB) automatically, or can be recognized as such using the beans.xml marker file. (The requirements of a CMB are set very low and basically just dictate the existence of a non-parameter constructor.)

This means that you should be able to use (read: inject) all JMBs with almost no extra effort.

However, problems will arise because JMBs use different scopes than CMBs (javax.faces.* vs. javax.enterprise.*)

These are best solved by registering a relative simple CDI-extension: When the CDI server (Tomcat for you) starts, it will raise a couple of events that you can observe - this is be the place where you can detect JMBs and convert them into correctly scoped CMBs.

But before you start hacking: All this has already been done by the Seam 3 Faces module. Simply put it in your classpath, and all JSF-scopes are bridged to CDI-scopes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!