Monday, August 24, 2015

Access Referenced Managed Bean in JSF

Following code can be used to reference one manged bean from another.

public class UsingBean 
    private NeededBean neededBean;

    public NeededBean getNeededBean()
    return neededBean;

    public void setNeededBean(NeededBean neededBean)
    this.neededBean = neededBean;

Now, you can use the following methods to call referenced managed bean property in JAVA class.

ELContext elContext = FacesContext.getCurrentInstance().getELContext();
NeededBean neededBean 
    = (NeededBean) FacesContext.getCurrentInstance().getApplication()
    .getELResolver().getValue(elContext, null, "neededBean");

---------------------------------- or --------------------------------------------

FacesContext facesContext = FacesContext.getCurrentInstance();
NeededBean neededBean
    = (NeededBean)facesContext.getApplication()

Reference site :-

No comments:

Post a Comment