且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用< ui:repeat>< h:inputText>在List< String>上不更新模型值

更新时间:2022-12-03 09:27:26

String类是不可变的,没有值的设置方法.吸气剂基本上是Object#toString()方法.

The String class is immutable and doesn't have a setter for the value. The getter is basically the Object#toString() method.

您需要直接在List上获取/设置值.您可以通过<ui:repeat varStatus>可用的列表索引来做到这一点.

You need to get/set the value directly on the List instead. You can do that by the list index which is available by <ui:repeat varStatus>.

<ui:repeat value="#{mrBean.stringList}" varStatus="loop">
    <h:inputText value="#{mrBean.stringList[loop.index]}" />
</ui:repeat>

您也不需要stringList的二传手. EL将通过List#get(index)获取项目,并通过List#add(index,item)设置项目.

You don't need a setter for the stringList either. EL will get the item by List#get(index) and set the item by List#add(index,item).