JSF howto link Beans
Don't be to hard on me, this is my first try with JSF.
I have a ManagedBean
with ApplicationScope
which shall hold some information for all visitors. Now it should be able to change the information in this bean, but I want that done from some 开发者_如何学Cother bean.
How can I link my beans? Is there some autowire
annotation or how do you build a datastructure with more than one bean?
With JSF2 you can inject one bean into another bean.
Inside faces-config.xml
use the following to inject visitorBean
to appScopeBean
.
<managed-bean>
<managed-bean-name>appScopeBean</managed-bean-name>
<managed-bean-class>com.app.AppScopeBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>visitorBean</property-name>
<value>visitorBean</value>
</managed-property>
</managed-bean>
Don't forget to add visitorBean field (with getters and setters) inside AppScopeBean.
精彩评论