更新时间:2022-12-01 09:34:07
String
类是不可变的。它没有实例值的setter。 getter在这个构造中基本上是由EL隐式调用的 Object#toString()
方法,它巧妙地返回字符串值本身。
The String
class is immutable. It doesn't have a setter for the instance value. The getter is in this construct basically the Object#toString()
method as implicitly called by EL, which coincidentally returns the string value itself.
您需要将更改的值设置为新的列表项。您可以通过列表中的大括号进行此操作,您可以通过列表索引:#{myBean.listOfStrings [index]}
。
You need to set the changed value as a new list item instead. You can do this via the brace notation on the list whereby you pass the list index: #{myBean.listOfStrings[index]}
.
所以,这应该做,使用 UIData#getRowIndex()
作为列表索引:
So, this should do, making use of UIData#getRowIndex()
as list index:
<h:dataTable binding="#{table}" value="#{myBean.listOfStrings}" var="row">
<h:column>
<h:inputText value="#{myBean.listOfStrings[table.rowIndex]}" />
</h:column>
</h:dataTable>
(注意:绑定的值表达式
是原样的!不要绑定到bean属性)
(note: the value expression of binding
is as-is! don't bind it to a bean property)