Depends on how the form is composed.
If each row of the table represents one form (i.e. the h:form
with h:inputText
and h:commandButton
is inside h:column
), then it's technically no problem.
<h:dataTable value="#{bean.list}" var="item">
<h:column>
<h:form>
<h:inputText value="#{bean.value}" />
<h:commandButton value="Submit" action="#{bean.submit}" />
</h:form>
</h:column>
</h:dataTable>
The problem is only that you need to figure to which row the input was related. The f:setPropertyActionListener
may be useful in this. But this approach hasn't my recommendation. Rather bind the input value (and if necessary also the action) to the iterated row object as declared in var
attribute of h:dataTable
instead. I.e. #{item.value}
and #{item.submit}
. Or, go for the approach described below.
If the whole table is placed inside a single form (i.e. the h:dataTable
is inside h:form
), then you'd better to set the value
attribute of the h:inputText
as a property of the iterated row object as declared in var
attribute of h:dataTable
.
<h:form>
<h:dataTable value="#{bean.list}" var="item">
<h:column><h:inputText value="#{item.value}" /></h:column>
</h:dataTable>
<h:commandButton value="Submit" action="#{bean.submit}" />
</h:form>
When you set it as a backing bean property, i.e. #{bean.value}
, it will always end up to be the value of the last row.