You do not need to do this. JSF does it for you. Just provide a fixed identifier if it is in the same scope.
<rich:dataGrid value="#{all}" var="item" columns="3"> <h:outputLabel value="#{item.name}" for="item" /> <h:selectBooleanCheckbox value="#{item.selectedForLaterUse}" id="item" /> </rich:dataGrid>
JSF will generate the correct HTML accordingly. Open the page in a browser, right-click and browse the source to see it yourself. The generated HTML element identifiers in this particular case consist of all the parent components of the NamingContainer
and the index of the current element.
Here is an example of the generated output, assuming that you pass all the NamingContainer
components a fixed identifier, for example <h:form id="form">
and <rich:dataGrid id="grid">
(otherwise JSF will auto- j_idt1
identifiers such as j_idt1
and etc. that will work fine, but not immediately readable):
<table id="form:grid" class="rf-dg"> <tbody id="form:grid:dgb" class="rf-dg-body"> <tr class="rf-dg-r"> <td class="rf-dg-c"> <label for="form:grid:0:item">one</label> <input id="form:grid:0:item" type="checkbox" name="form:grid:0:item" /> </td> <td class="rf-dg-c"> <label for="form:grid:1:item">two</label> <input id="form:grid:1:item" type="checkbox" name="form:grid:1:item" /> </td> <td class="rf-dg-c"> <label for="form:grid:2:item">three</label> <input id="form:grid:2:item" type="checkbox" name="form:grid:2:item" /> </td> </tr> </tbody> </table>
source share