CDI bean constructor and @PostConstruct called multiple times

后端 未结 1 593
无人共我
无人共我 2020-12-10 21:30

After some experimentation, this appears to be an issue when using a CDI bean, and nothing to do with PrimeFaces which is what I originally assumed.

If I change the

相关标签:
1条回答
  • 2020-12-10 21:52

    Here's your first piece of advice with CDI and JSF - Never mix CDI with JSF annotations.

    Your problem is that you use @javax.inject.Named a CDI annotation with javax.faces.bean.SessionScoped - a JSF annotation.

    In CDI you would do:

    import javax.enterprise.context.SessionScoped;
    import javax.inject.Named;
    
    @Named(value = "tableBeanLazy")
    @SessionScoped
    public class TableBeanLazy {...}
    

    Note that the above will work perfectly fine with JSF.

    In a pure JSF way you would do:

    import javax.faces.bean.SessionScoped;
    import javax.faces.bean.ManagedBean;
    
    @ManagedBean(value = "tableBeanLazy")
    @SessionScoped
    public class TableBeanLazy {...}
    

    I would recommend sticking with CDI all the way. However, CDI currently does not provide an alternative for the JSF @javax.faces.bean.ViewScoped out of the box. To get it in CDI look into Apache Deltaspike.

    0 讨论(0)
提交回复
热议问题