开发者

JSF howto link Beans

开发者 https://www.devze.com 2023-04-02 09:35 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消