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

前端 未结 1 765
情话喂你
情话喂你 2021-01-03 04:13

I have a Tomcat 6 JSF web application that I\'d like to set up with CDI beans. I will have to convert the project to CDI gradually though.

My question is: can CDI b

相关标签:
1条回答
  • 2021-01-03 04:43

    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.

    0 讨论(0)
提交回复
热议问题