What is the "for" label for selectBooleanCheckbox

How do I link each individual flag in the output table so that when I click on the item’s label it would be virtually the same as if I clicked on the flag?

<rich:dataGrid value="#{all}" var="item" columns="3"> <h:outputLabel value="#{item.name}" for="what_here?" /> <h:selectBooleanCheckbox value="#{item.selectedForLaterUse}" id="item#{item.id}" /> </rich:dataGrid> 

The probability that comes first to mind, of course, is

  for="item#{item.id}" 

but since jsf id are relative, this will not work, right?

There is also one use case for selectManyCheckbox, but this does not seem to make it possible to use columns.

+4
source share
1 answer

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> 
+7
source

All Articles