How to get managedbean property from another bean in JSF

放肆的年华 提交于 2019-11-28 17:58:06

The @ManagedProperty declares the location where JSF should set the property, not where JSF should "export" the property. You need to just inject the LoginBean as property of OrderBean.

public class OrderBean {

    @ManagedProperty(value="#{loginBean}")
    private LoginBean loginBean; // +setter

    // ...
}

This way you can access it in the OrderBean by just

loginBean.getIdentityNr();

Alternatively, if you make your OrderBean request or view scoped, then you can also set only the identityNr property.

public class OrderBean {

    @ManagedProperty(value="#{loginBean.identityNr}")
    private String identityNr; // +setter

    // ...
}

Unrelated to the concrete problem: initializing String properties with an empty string is a poor practice.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!