Wednesday, June 12, 2013

Retrieving Managed Beans Programmatically

Incase of ADF applications, sometimes we need to access one managed bean properties from another managed bean. Following code provides details on how to access managed beans programmatically specified in different scopes.

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

ExternalContext exctx = FacesContext.getCurrentInstance().getExternalContext();

AppBean appBean = (AppBean) exctx.getApplicationMap().get("appBeanName");
SessionBean sessionBean = (SessionBean) exctx.getSessionMap().get("sessionBeanName");
RequestBean sessionBean = (RequestBean) exctx.getRequestMap().get("requestBeanName");

AdfFacesContext adfctx = AdfFacesContext.getCurrentInstance();

ViewBean viewBean = (ViewBean)adfctx.getViewScope().get("viewBeanName");
PageFlowBean pageFlowBean = (PageFlowBean)adfctx.getPageFlowScope().get("pageFlowBeanName");

5 comments:

  1. Dumass page implementation, can't copy paste your bullshit

    ReplyDelete
    Replies
    1. I think it's not possible to copy/paste bullshit..what do you say!

      Delete
    2. If he does not want other to copy the code by disabling the right click why publish at all?
      Just use Ctrl A+Ctrl C and copy the code

      Delete
    3. are you getting paid to copy/paste the code from online?

      Delete

Provide your thoughts !