Correct way to manage multiple h: inputText?
I have h:dataTable
to display information about my item (in my case a support request) and for each line I would like to add h:inputText
and h:commandButton
to add a comment to the item I need, I have no problem with the action, but my question is about the correct way to control many h:inputText
and related meanings on backbean
.
I'm not sure if it is correct for everyone to h:inputText
set the value to the same property backbean
. Any suggestions? Thanks everyone.
a source to share
Depends on how the shape is formed.
If each row of the table represents a single shape (i.e. h:form
with h:inputText
and h:commandButton
is inside h:column
), then technically this is not a 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 only problem is that you need to determine which row the input was linked to. This can be helpful f:setPropertyActionListener
. But this approach doesn't have my recommendation. Rather, bind the input value (and optionally the action) to the iterated string object as specified in the attribute var
h:dataTable
. That is #{item.value}
and #{item.submit}
. Or go for the approach described below.
If the whole table fits inside one form (i.e. h:dataTable
is inside h:form
), then you are better off setting the attribute value
h:inputText
as a property of the repeating row of the object declared in the attribute var
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 , it will always be the last string value . #{bean.value}
a source to share