JSF 2.2:ui:repeat 使用 varStatus 动态生成的 HtmlInputText 失败

JSF 2.2: ui:repeat with dynamically generated HtmlInputText using varStatus failed

我只想动态生成 HtmlInputFields,在这个示例中我只生成了 3 个字段。在 out.xhtml 中,我想使用 ui:repeat 渲染这些组件,并使用 binding 属性(不是值!! ).

使用绑定属性时,与 varStatus 一起使用的 loop.index 总是失败。

异常:

binding="#{loop.index}": Target Unreachable, identifier 'loop' resolved to null

out.xhtml:

<ui:repeat value="#{myBean.htmlInputs}" varStatus="loop" var="bItem">
  <!-- THIS WORKS -->
  <h:inputText value="#{loop.index}" />
  <!-- THIS WORKS -->
  <h:inputText value="#{myBean.htmlInputs[0]}" />
  <!-- THIS WORKS ALSO -->
  <h:inputText binding="#{myBean.htmlInputs[0]}" />
  <!-- AND THIS FAILES ?? WHY ?? -->
  <h:inputText binding="#{myBean.htmlInputs[loop.index]}" /><p/> 
</ui:repeat>

MyBean.java

@Named
@SessionScoped
public class BookingBean implements Serializable {
  private List<HtmlInputText> htmlInputs = new ArrayList<>();

  @PostConstruct
  public void init() {
    HtmlInputText hInput;
    for (int i=0 ; i<3 ; i++) {
      hInput = new HtmlInputText();
      hInput.setValue("item #:" + i);
      htmlInputs.add( hInput );
    }
  }

  public List<HtmlInputText> getHtmlInputs() {
    return htmlInputs;
  }

  public void setHtmlInputs(List<HtmlInputText> htmlInputs) {
    this.htmlInputs = htmlInputs;
  }
}

我现在的问题是: 我如何在 JSF 2.2 中通过 ui:repeat 正确使用动态生成的 JSF 组件的绑定?

谢谢

评估所有绑定属性(以及 id attribtues and taghandlers like JSTL) during the

ui:repeatRender phase (later) 期间处理。

你不应该绑定你的输入,你可能对它们的值感兴趣,所以在值字段中使用相关的表达式(到 bean)