简体   繁体   English

在h:dataTable中忽略了JSF输入ID

[英]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. 每个字段都有一个在辅助bean中定义的ID,因此我想使用该ID来标识每个h:inputText字段。

<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 . 当我尝试查看页面时,JSF会生成错误: 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: 如果我在输入ID属性中添加一个常量,它可以工作,但是查看生成的ID时,不包括项目的ID:

<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? 有没有办法在输入id属性中包含迭代项的id? Why is the ID omitted? 为什么省略ID?

Why is the ID omitted? 为什么省略ID?

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. 在视图构建期间, #{item}不可用。

Why do you need a different ID? 为什么需要不同的身份证? Just give it a fixed ID. 只需给它一个固定的ID。 JSF will take care about its uniqueness in the generated HTML output. JSF将在生成的HTML输出中关注其唯一性。 The generated ID is very predictable and you can easily hook on that by JavaScript, if that is your intent. 生成的ID是非常可预测的,如果这是您的意图,您可以通过JavaScript轻松地将其挂钩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM