Recently we have seen a blog entry: "JSF: IDs and clientIds in Facelets", which provided wrong implementation of the feature.
I'm not sure how useful it is, but here is our approach to the same problem.
In the core is ScopeComponent. Example uses a couple of utility functions defined in Functions. Example itself is found at window.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jstl/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:ex="http://www.nesterovsky-bros.com/jsf"> <body> <h:form> <ui:repeat value="#{ex:sequence(5)}"> <f:subview id="scope" binding="#{ex:scope().value}"> #{scope.id}, #{scope.clientId} </f:subview> <f:subview id="script" uniqueId="my-script" binding="#{ex:scope().value}" myValue="#{2 + 2}"> , #{script.id}, #{script.clientId}, #{script.bindings.myValue.expressionString}, #{ex:value(script.bindings.myValue)}, #{script.attributes.myValue} </f:subview> <br/> </ui:repeat> </h:form> </body> </html>
Update: ex:scope() is made to return a simple bean with property "value".
Another useful example:
<f:subview id="group" binding="#{ex:scope().value}"> <h:inputText id="input" value="#{bean.property}"/> <script type="text/javascript"> var element = document.getElementById('#{group.clientId}:input'); </script> </f:subview>