Sunday, January 23, 2011

Some handy code for your managed Beans ( ADF & JSF )

Back in 2009, I already a made a blogpost about some handy code which you can use in your ADF Web Application. You can say this blogspot is part 2 and here I will show you the code, I use most  in my own managed Beans.

I start with FacesContext class, with this class you can use to find a JSF Component, change the Locale, get the ELContext, Add a message to your view and get the ExternalContext
The ExternalContext class, with this you can retrieve all the java init & context (web.xml) parameters, the Request & Session parameters and your web application url.
AdfFacesContext class, you can use this class for Partial Page Rendering ( PPR), get the PageFlowScope and ViewScope variables
ADFContext class, with this you can get all the memory scopes variables even the application scope variables, ELContext and the SecurityContext.
SecurityContext class, retrieve the current user and its roles.
BindingContext, BindingContainer and DCBindingContainer class. These classes are well known when you want to retrieve the ADF pagedef objects.
The last class is ControllerContext, which you can use to retrieve the exceptions

10 comments:

  1. Hi Edwin,
    I am making a method call to a db stored function in ADF and exposing that method as a client interface. I want to store the value returned from the method into ADFContext applicationscope. The value is later shown on all pages of the UI. Should I create a managed bean applicationscope to containing calling method code? Not sure how to achieve this functionality.

    Thanks
    Jacob

    ReplyDelete
  2. Hi

    You can store the method result in a sessionscope variable or in a page flow scope when it only needs to be seen in that task flow
    You only need to call this method in a bean and set the result in a session or pageflowscope var.

    Thanks

    ReplyDelete
  3. can we store java.util.list in pageFlowScope?

    ReplyDelete
  4. How can we get HttpServletRequest inside the managed bean?

    ReplyDelete
    Replies
    1. Hi,

      you mean this
      FacesContext context = FacesContext.getCurrentInstance();
      HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();

      thanks

      Delete
  5. Hi Edwin,

    Useful post. I got a confusion here. What is the difference between following:

    FacesContext.getCurrentInstance().getELContext(); and
    ADFContext.getCurrent().getELContext();

    AdfFacesContext.getCurrentInstance().getPageFlowScope(); and
    ADFContext.getCurrent().getPageFlowScope();

    I might be missing something obvious, but will be thankful if u can please make it clear or give any reference.

    Thanks

    ReplyDelete
    Replies
    1. Hi,

      Nothing, they do the same, maybe it is handy that you that you don't need to use both and maybe FacesContext can be changed in the future and the Oracle one won't be changed.

      thanks

      Delete
  6. Edwin:
    Great post. Thank you.
    Krishna

    ReplyDelete
  7. Edwin,

    One of useful post

    ReplyDelete