RE: Finding a component with a specific id
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
RE: Finding a component with a specific id
You might already have looked this up; the JavaDoc for UIComponent has an extensive description of the lookup algorithm used: http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/api/index.html - Brendan -Original Message- From: Simon Kitching [mailto:[EMAIL PROTECTED] Sent: Monday, October 24, 2005 11:07 PM 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
Re: Finding a component with a specific id
Kirchgessner, Lisa wrote: 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. And a very good guess it was too. The old JSF/JSP problem of components being created and rendered in the same pass. Thanks! Oh how I wish we were using Facelets! Cheers, Simon