wood burning stoves 2.0*
The moose likes JSF and the fly likes fetch each component on a JSF page and check if id attribute is there. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "fetch each component on a JSF page and check if id attribute is there. " Watch "fetch each component on a JSF page and check if id attribute is there. " New topic
Author

fetch each component on a JSF page and check if id attribute is there.

sree javab
Greenhorn

Joined: May 05, 2008
Posts: 9
I want to fetch each component on a given JSF page and check if that component has an Id attribute. If the component has no Id attribute to it, then assign an attribute Id with a customised value. (this is required to be done in my project). I know in JSF, if no id attribute is specified a default id is given to components, but it is different every time. I want the Id attribute's value to be the same every time the page loads. (The JSF pages have been written long back with no id attributes to components.)
Can anyone please let me know what could be the best way to do it.
Max Jonas Werner
Greenhorn

Joined: Nov 27, 2008
Posts: 2
Hi sree,

to answer your question, not taking into account that there could be a better solution to your actual problem (different IDs): What about fetching the UIViewRoot calling FacesContext.getCurrentInstance().getViewRoot() and then iterating over the children with UIViewRoots getChildren method. Fetching the children should then be implemented recursively e.g.

BTW: I find this a very ugly approach to solving your problem. You should probably consider a different solution which e.g. is not dependent on the IDs. Perhaps you can just explain the case in more detail.

HTH,
Max
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: fetch each component on a JSF page and check if id attribute is there.