且构网

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

使用 <ui:repeat><h:inputText>在列表<字符串>上不更新模型值

更新时间:2022-12-03 09:41:15

String 类是不可变的,并且没有值的 setter.getter 基本上是 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 上获取/设置值.您可以通过 提供的列表索引来实现.

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 的 setter.EL 将通过 List#get(index) 获取 item 并通过 List#add(index,item) 设置 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).