How can I retrieve an object on @WindowScoped?

后端 未结 1 433
青春惊慌失措
青春惊慌失措 2021-01-25 08:08

In this post Dynamic ui:include I asked how I could store an object in some state that could permit me to load a new windows, or tab, of the same browser and it was not stored a

相关标签:
1条回答
  • 2021-01-25 09:06

    You're trying to get the LoginBean from the session map. This works only for session scoped beans with the standard JSF @SessionScoped annotation.

    The canonical way to access other beans is using @ManagedProperty on the retrieving bean.

    E.g.

    @ManagedBean
    @RequestScoped
    public class OtherBean {
    
        @ManagedProperty("#{logicBean}")
        private LogicBean logicBean;
    
        // Getter+Setter.
    }
    

    If you really need to access it inside the method block by evaluating the EL programmatically, you should be using Application#evaluateExpressionGet() instead:

    FacesContext context = FacesContext.getCurrentInstance();
    LogicBean logicBean = context.getApplication().evaluateExpressionGet(context, "#{logicBean}", LogicBean.class);
    // ...
    
    0 讨论(0)
提交回复
热议问题