You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Simon Kitching <sk...@obsidium.com> on 2005/10/25 06:06:45 UTC
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