i referred to this question and i’ve a similar problem
JSF – Get the SessionScoped Bean instance
I want to get the current instance of a managed bean in another managed bean. I’ve a SuperBean which is extended in a base Class – baseBean.
I set the value of a list – itemList in baseBean. The getter setter of the list are in SuperBean and I should use this SuperBean in my BackingBean to get the value of the itemList.
I tried using –
Application app = FacesContext.getCurrentInstance().getApplication();
ValueBinding vb = app.createValueBinding("#{superbean}");
SuperClass superclass = (SuperClass) vb.getValue(FacesContext.getCurrentInstance());
When I try to print superclass.getItems(); – It gives only this – []
And also this –
SuperClass superclass = (SuperClass)FacesContext.getCurrentInstance().
getExternalContext().getSessionMap().get("superbean");
When I try to print with this – It throws exception as my superbean entry is not present in the sessionMap even though the entry is placed in facesConfig and also as @ManagedBean and @sessionscoped
Kindly help me resolve this.
You can inject a managed bean into another if the injected bean has the same or broader scope. Here is an example: