0

I tried the following code:

 <ui:repeat var="item" id="request" value="#{myBean.requestList}">
    <h:selectBooleanCheckBox id="#{item.name}" value="#{item.type}"/>
    <h:outputText value="#{item.name}"/>
</ui:repeat>

I also tried

 <ui:repeat var="item" id="request" value="#{myBean.requestList}">
        <ui:param name="dynamicVal" value="#{item.name}"/>
        <h:selectBooleanCheckBox id="#{dynamicValue}" value="#{item.type}"/>
        <h:outputText value="#{item.name}"/>
  </ui:repeat>

Both of these give an error:

java.lang.IllegalArgumentException: component identifier must not be a xero-length String at javax.faces.component.UIComponentBase.isIdValid ..

Whats incorrect in this code? How can I assign dynamic id to the check box suhc that both the label & the id are same. I need this for automaton.

Shikha Dhawan
  • 1,414
  • 8
  • 27
  • 44

1 Answers1

4

The id attribute is evaluated during view build time, but the <ui:repeat> runs during view render time. Essentially, your IDs end up being null which is indeed invalid.

Just don't try to manually assign generate IDs. The <ui:repeat> will already automatically insert the current iteration index in the client ID. This example,

<h:form id="formId">
    <ui:repeat ...>
        <h:outputLabel for="checkboxId" ... />
        <h:selectBooleanCheckBox id="checkboxId" ... />
    </ui:repeat>
</h:form>

will end up like

<form id="formId">
     <label for="formId:0:checkboxId">...</label>
     <input type="checkbox" id="formId:0:checkboxId" />
     <label for="formId:1:checkboxId">...</label>
     <input type="checkbox" id="formId:1:checkboxId" />
     <label for="formId:2:checkboxId">...</label>
     <input type="checkbox" id="formId:2:checkboxId" />
     ...
</form>

If you're absolutely positive that you need to manually fiddle with IDs like that, then use <c:forEach> instead. It runs during view build time, generating physically multiple JSF components. You can use <c:forEach var> and varStatus in the id attribute.

See also:


By the way, have you considered <h:selectManyCheckbox> for the purpose?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I have a button. I need to update on few components after a response is returned. Ajax is not working as expected. The components which I expect to be updated are not getting updated. I have disbaled partial view state saving, still the view is not getting updated. How can this be handled? – Shikha Dhawan Jul 04 '13 at 06:09
  • You seem to have a new question. Just press `Ask Question` button to ask a new question instead of posting it as a comment on an answer to a different question. – BalusC Jul 04 '13 at 11:25