CDI托管bean和JSF托管bean可以相互通信吗? [英] Can CDI managed beans and JSF managed beans talk to each other?

查看:150
本文介绍了CDI托管bean和JSF托管bean可以相互通信吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Tomcat 6 JSF Web应用程序,我想用CDI bean设置它。我将不得不逐渐将项目转换为CDI。

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.

我的问题是:可以将CDI bean和传统的JSF托管bean互相注入吗?

My question is: can CDI beans and traditional JSF managed beans be injected into each other?

谢谢。

推荐答案

所有JSF托管bean(JMB)都是CDI托管bean( CMB)自动,或使用 beans.xml 标记文件可以识别。 (CMB的要求设置得非常低,基本上只需要指定存在非参数构造函数。)

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.)

这意味着您应该能够使用(读取:注入)几乎没有额外努力的所有JMB。

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

但是,由于JMB使用与CMB不同的范围( javax.faces。* vs. javax.enterprise。*

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

通过注册相对简单的CDI可以最好地解决这些问题-extension:当CDI服务器(Tomcat for you)启动时,它会引发一些您可以观察到的事件 - 这是您可以检测JMB并将其转换为正确范围的CMB的地方。

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.

但在开始黑客攻击之前:所有这些都已经由 Seam 3 Faces模块。只需将它放在类路径中,所有JSF范围都桥接到CDI范围。

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.

这篇关于CDI托管bean和JSF托管bean可以相互通信吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆