问题描述
我有一个会话bean
I have a session bean
<managed-bean>
<managed-bean-name>vdcAddBean</managed-bean-name>
<managed-bean-class>com.cloud.appsportfolio.jsf.vdc.beans.VDCAddBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
现在,我将这个bean注入到一个请求中:
Now, I am injecting this bean into a request one:
<managed-bean>
<managed-bean-name>providerSelectionBean</managed-bean-name>
<managed-bean-class>com.cloud.appsportfolio.jsf.sourcing.ProviderSelectionBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>vdcAddBean</property-name>
<property-class>com.cloud.appsportfolio.jsf.vdc.beans.VDCAddBean</property-class>
<value>#{sessionScope.vdcAddBean}</value>
</managed-property>
</managed-bean>
好吧,当我用providerSelectionBean
java代码访问vdcAddBean时,我收到了NPE,因为vdcAddBean
尚未初始化.如果我要先进入菜单,那么在后端具有vdcAddBean
并返回到providerSelectionBean
的页面中,所有工作都很好,因为似乎vdcAddBean
已经初始化.
Well, when I'm accessing vdcAddBean in providerSelectionBean
java code, I receive a NPE because vdcAddBean
is not yet initialized. If I'm going first in my menu, in a page which has vdcAddBean
in the back-end and comes back to providerSelectionBean
all works great because it seems that vdcAddBean
was already initialized.
问题是:在访问providerSelectionBean
bean时如何强制vdcAddBean初始化(如果为null)?
The question is: how I can force vdcAddBean to be initialized (if it's null) when accessing providerSelectionBean
bean?
谢谢.
推荐答案
替换
<value>#{sessionScope.vdcAddBean}</value>
作者
<value>#{vdcAddBean}</value>
让JSF自动创建bean.
to get JSF to autocreate the bean.
这篇关于自动实例化会话bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!