1

I have

<wai:collectionIter value="#{listModel.listRows}" valueVar="listRow" odd="odd" even="even" styleVar="rowStyle">
  <tr class="#{rowStyle}">
    <td>
      <h:selectBooleanCheckbox value="#{listRow.rowSelected}" disabled="#{detailModel.readOnly}">
        <c:set target="#{component}" property="id" value="#{listRow.rowData.name}"/>
      </h:selectBooleanCheckbox>
    </td>
    <ui:insert name="columnData"/>
  </tr>
</wai:collectionIter>

(where wai:collectionIter is a custom tag)

but the corresponding html code looks like

<td>
  <c:set target="javax.faces.component.html.HtmlSelectBooleanCheckbox@10cd160" property="id" value="BusinessUnitNumber"></c:set><input type="checkbox" name="searchForm:j_idt100" /
</td>

I must say that c:set target="#{component}" comes from an example I found elsewhere ...

As I'm not a JSF expert and assuming that it is correct, I expected that the resulting html was something like this:

<td>
  <input id="BusinessUnitNumber" type="checkbox" name="BusinessUnitNumber"
</td>

Is it completely wrong or do I miss something else?

Thank you for any help.

Francesco

Francesco
  • 2,350
  • 11
  • 36
  • 59

2 Answers2

2

Just use a standard JSF iterating component instead of a vague custom tag. E.g. <ui:repeat>:

<ui:repeat value="#{listModel.listRows}" var="listRow" varStatus="loop">
    <tr class="#{loop.even ? 'even' : 'odd'}">
        <td>
            <h:selectBooleanCheckbox 
                id="foo" 
                value="#{listRow.rowSelected}" 
                disabled="#{detailModel.readOnly}" />
        </td>
        <ui:insert name="columnData"/>
    </tr>
</ui:repeat>

It'll worry about uniqueness of the IDs. It will prepend the row index to the given fixed ID like follows:

<tr class="odd"><td><input type="checkbox" name="formid:repeatid:0:foo" id="formid:repeatid:0:foo" /></td></tr>
<tr class="even"><td><input type="checkbox" name="formid:repeatid:1:foo" id="formid:repeatid:1:foo" /></td></tr>
<tr class="odd"><td><input type="checkbox" name="formid:repeatid:2:foo" id="formid:repeatid:2:foo" /></td></tr>

You can make it dynamic by id="#{listRow.rowData.name}", but that's not necessary.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

Francesco,

You try this:

<h:selectBooleanCheckbox id="#{listRow.rowData.name}" value="#{listRow.rowSelected}" disabled="#{detailModel.readOnly}" />
Bruno Arueira
  • 314
  • 1
  • 4
  • 17
  • Hello Bruno,sorry but I forgot a (important) piece of code in the first code-snipped. I added it now. – Francesco Sep 22 '11 at 11:59
  • Francesco, when I was used jsf the component ids area dynamilly and you put configured id similar to code was posted by me. Try and return some doubt. – Bruno Arueira Sep 22 '11 at 12:05
  • Bruno, I didn't really understand what do you mean, so I figured out you want that I put in your code anyway. ` `. I did and now I get "javax.servlet.ServletException: Empty id attribute is not allowed" – Francesco Sep 22 '11 at 12:13
  • The closest you will get your result will be something like searchForm:BusinessUnitNumber because searchForm works as a container and the ids will be nested. This [link](http://stackoverflow.com/questions/316790/dynamic-ids-in-jsf-seam/326389#326389) explain better. – Bruno Arueira Sep 22 '11 at 12:26