0

Using expression language, how can I access a component that is bound and repeated in a datatable?

<h:dataTable value="#{bean.items}" var="item" id="table">
    <h:column>
        <h:inputText value="#{item.name}" id="name" binding="#{mybinding}"/>
    </h:column>
</h:dataTable>

Should I give each binding a generated name with a concatenation of a literal and the row index, for instance ('mybinding_1', 'mybinding_2', and so forth), and if so, how?

Or instead is there a way to get a particuliar element with #{mybinding} plus some kind of brace notation ([])?

Virginie
  • 909
  • 3
  • 12
  • 32

1 Answers1

1

There's a misconception going here. There are definitely not physically multiple <h:inputText> components in the component tree. There's only one component whose HTML representation is generated multiple times depending on the current state of the parent table component. You can confirm this by walking through the component tree starting at FacesContext#getViewRoot(), you'll ultimately find only one <h:inputText> component.

So, binding="#{mybinding}" is perfectly fine.

If you're having problems with it, it's caused elsewhere and needs to be solved differently. Only and only if you're using a view build time tag to generate physically multiple components in a loop, such as JSTL <c:forEach>, then there would indeed be physically multiple <h:inputText> components in the component tree and you'd need to bind them to an array or map. But this is currently clearly not the case.

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