Have you tried putting the colSelector after the datatable?  It sounds
like the view does not yet contain the table. I thought myFaces had
similar issues with the DataScroller in ealier versions (maybe still
do).  Maybe take a look on how they handled?

Of course, just a guess.

Good luck

-----Original Message-----
From: Simon Kitching [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 25, 2005 12:07 AM
To: MyFaces Discussion
Subject: Finding a component with a specific id


Hi,

 From a custom renderer I need to be able to find a component with a 
specific id.

Page:
   <o:colSelector tableId="table1" .../>

   <t:dataTable id="table1" ...>
      ..
   </t:dataTable>

 From the renderer for the o:colSelector I've tried:
   UIComponent table =
facesContext.getViewRoot().findComponent(tableId);
   UIComponent table = component.findComponent(tableId);
   UIComponent table = component.findComponent(":" + tableId); but had
no luck.

The table is enclosed in a subview named "body", so the id actually gets

output as "body:table1". I've tried all the above with that string too, 
and no luck.

Any ideas how I should locate that table component by id??
[And BTW, is it possible for a component in a naming container to have 
an id that is *not* prefixed by its NamingContainer parent's id?]


On a related note, looking at the source for UIComponent.findComponent, 
I see it calls _ComponentUtils.findComponent which is as follows.

     static UIComponent findComponent(UIComponent findBase, String id)
     {
         if (idsAreEqual(id,findBase))
         {
             return findBase;
         }

         for (Iterator it = findBase.getFacetsAndChildren();
           it.hasNext(); )
         {
             UIComponent childOrFacet = (UIComponent)it.next();
             if (!(childOrFacet instanceof NamingContainer))
             {
                 UIComponent find = findComponent(childOrFacet, id);
                 if (find != null) return find;
             }
             else if (idsAreEqual(id,childOrFacet))
             {
                 return childOrFacet;
             }
         }

         return null;
     }

What's the point of that "instanceof NamingContainer"? Why doesn't the 
search recurse into NamingContainer children of findBase?

Thanks,

Simon

Reply via email to