开发者

JSF Input ID ignored inside h:dataTable

I have a simple data table which contains dynamic form text fields. Each field has an ID defined in the backing bean, so I wanted to use that ID to identify each of the h:inputText fields.

<h:dataTable id="fieldTable" value="#{bean.indexFields}" var="item">
  <h:column id="column">
    <h:inputText id="#{item.id}" value="#{bean.values[item.id]}" />
  </h:column>
</h:dataTable>

When I try to view the page, JSF generates an error: The id attribute may not be empty.

If I add a constant to the input ID attribute, it works, but looking at the generated ID the item's ID is not included:

<h:inputText id="#{item.id}abc" value="#{bean.values[item.id]}" />

This generates the following output:

<table id="form:fieldTable">
  <tbody>
    <tr>
      <td><input id="form:fieldTable:0:abc" type="text" name="form:fieldTable:0:abc" title="" /></td>
    </tr>
    <tr>
      <td><input id="form:fieldTable:1:abc" type="text" name="form:fieldTable:1:abc" title="" /></td>
    </tr>
    <tr>
      <td><input id="form:fieldTable:2:abc" type="text" name="form:fieldTable:2:abc" title="" /></td>
    </tr>
  </tbody>
</table>

Is there a way to include the id from the iterated item in the input id attribute? Why is开发者_运维技巧 the ID omitted?


Why is the ID omitted?

Because there's only one component in the view tree. It's only its generated output which get repeated. The #{item} is not available during view build time.

Why do you need a different ID? Just give it a fixed ID. JSF will take care about its uniqueness in the generated HTML output. The generated ID is very predictable and you can easily hook on that by JavaScript, if that is your intent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜