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.
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.