JSF application scope instantiation and injection

后端 未结 2 1016
鱼传尺愫
鱼传尺愫 2021-02-20 08:11

Probably my question is a trivial one, but I never used an application scope bean before. I need the application bean because I have to do time consuming transactions on the dat

2条回答
  •  渐次进展
    2021-02-20 08:32

    Since I had the same problem, and I used @BalusC code to solve it, I feel there is maybe just something to add here.

    Question author stated that:

    After I read that if I want to inject the application bean into another bean I have to use @PostConstuct annotation

    This was exactly my problem. I did everything like BalusC did in his answer, except I didn't have Application Bean used in any manner in Session Bean's init() method. So, I added

    @ManagedBean
    @SessionScoped
    public class TestsBean implements Serializable {
    
    @PostConstruct 
    init(){
    ....
    System.out.println("appbean session init size" + appbean.getPinovi().size());
    ....
    } 
    

    This is what I had to do to get it working, just put appBean into use somehow. It looks like hack, though...

提交回复
热议问题