Forum Stats

  • 3,852,300 Users
  • 2,264,088 Discussions
  • 7,905,022 Comments

Discussions

How to call partial trigger on JSFF component from separate managed bean?

eevictim
eevictim Member Posts: 319
edited Nov 18, 2010 5:00AM in JDeveloper and ADF
Guys and Gals,

Using JDev 11.1.1.2.0. Looked on the forums and google. Initial results aren't so great.

Is it possible to call a PPR on a JSFF component from a separate managed bean? It seems calling the FacesContext in this instance calls the root JSPX, which only contains one child: the RichDocument.
      UIComponent component =
         FacesContext.getCurrentInstance().getViewRoot().findComponent("pc1:table1");
      if (component != null)
      {
         AdfFacesContext context = AdfFacesContext.getCurrentInstance();
         context.addPartialTarget(component);
      }
      System.out.println(FacesContext.getCurrentInstance().getViewRoot().getChildCount());
Returns 1 :(

Ideas for a workaround?

Edited by: LovettWB on Nov 17, 2010 3:39 AM

Edited by: LovettWB on Nov 17, 2010 4:11 AM

Edited by: LovettWB on Nov 17, 2010 4:12 AM

Best Answer

Answers

  • eevictim
    eevictim Member Posts: 319
    If not possible, refreshing the entire JSFF would work. This refresh request is being sent from a managed bean connected to a dialog from within the JSFF. i.e. I'm not refreshing a region on a page, but the JSFF itself.
  • Hi,

    Bind the component to the managed bean first (in component inspector Advanced > Binding), JDeveloper will create the getter/setter methods for you automatically. After that you can call AdfFacesContext.getCurrentInstance().addPartialTarget(propertyName) to refresh the component.

    Regards,

    Joonas
    Joonas Linkola-Oracle
  • eevictim
    eevictim Member Posts: 319
    My component is in another, separate, managed bean.

    partTable is in bean TableCollectionListeners

    My PPR is being called from DialogCollectionListeners

    In this instance, how would I grab the handle for the component (partTable) so my DialogCollectionListener bean could "see" it for the AdfFacesContext.getCurrentInstance().addPartialTarget(propertyName)? I thought the ....findComponent("pc1:table1"); command would work, but it doesn't seem to find it.

    I apologize. Should have cleared that up in my previous post.
  • Joonas Linkola-Oracle
    Joonas Linkola-Oracle Member Posts: 277
    Answer ✓
    Then maybe this post will help (assuming your fragment is added to the page as a region): http://biemond.blogspot.com/2009/11/find-uicomponent-in-adf-task-flow.html
  • eevictim
    eevictim Member Posts: 319
    Looks promising! Thank you for your reply. I'll check it out in the morning, and let you know how it goes. I'm pooped!
  • eevictim
    eevictim Member Posts: 319
    Thanks! Joonas, you've been a great help.

    The code on the page you referenced was close, but the code on a page referenced in the user comments was even better:

    http://www.jroller.com/mert/entry/how_to_find_a_uicomponent

    My region is located in a facet, which the page you posted doesn't quite cover, but the page above fixed that. Here's the fix below:

    In Managed Bean
          // search for the region ID (or task flow) in the base page
          UIComponent base = jsfUtils.findComponentInRoot("dynamicRegion");
          // now find component ID from within that region
          UIComponent partTable = jsfUtils.findComponent(base, "partTable");
          // call PPR on your found component
          AdfFacesContext.getCurrentInstance().addPartialTarget(partTable);
    In JSFUtils utility class
       
       // used to locate region.  Could also find any component
       // located in the base ViewRoot()
       public static UIComponent findComponentInRoot(String id) {
        UIComponent component = null;
    
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (facesContext != null) {
          UIComponent root = facesContext.getViewRoot();
          component = findComponent(root, id);
        }
    
        return component;
    }
        // Recursive method which finds your component within JSFF
        // regardless of facet or other UIComponents which may have children
    
    public static UIComponent findComponent(UIComponent base, String id) {
        if (id.equals(base.getId()))
          return base;
      
        UIComponent kid = null;
        UIComponent result = null;
        Iterator kids = base.getFacetsAndChildren();
        while (kids.hasNext() && (result == null)) {
          kid = (UIComponent) kids.next();
          if (id.equals(kid.getId())) {
            result = kid;
            break;
          }
          result = findComponent(kid, id);
          if (result != null) {
            break;
          }
        }
        return result;
    }
    Good stuff to know!
  • eevictim
    eevictim Member Posts: 319
    One more thing.

    To do an effective search on a component ID, I believe you have to manually change the component's ID. If you let ADF assign the ID, there's no telling what the ID will become at runtime, which makes for an uncertain search outcome.
  • Glad to hear you got it working!

    You're safe with JDeveloper generated component IDs (pc1, t1 etc.), but may run into problems if you don't have IDs assigned at design time at all (in which case they get generated at runtime).
    Joonas Linkola-Oracle
This discussion has been closed.