@ManagedProperty does not reflect changes and keeps returning null

后端 未结 5 2010
花落未央
花落未央 2021-01-14 11:07

I\'m trying to inject the value of one sessionscoped bean into a viewscoped bean but it keeps returning null, here\'s a snippet:

import javax.faces.applicati         


        
5条回答
  •  死守一世寂寞
    2021-01-14 11:24

    Recently I have problem with injecting nested managed bean properties by @ManagedProperties too. Once injected it never changed. I did a workaround by evaluating EL in getter instead of injecting it.

    Try that:

    public String getUserName() {
        FacesContext context = FacesContext.getCurrentInstance();
        return (String) context.getApplication().evaluateExpressionGet(context,"#{user.userName}", String.class);
    }
    

    You can also try injecting entire user bean and get userName field from it in getter.

提交回复
热议问题