作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是场景(简化):
有一个具有成员和适当的getter/setter的bean(称为mrBean
):
private List<String> rootContext;
public void addContextItem() {
rootContext.add("");
}
<h:form id="a_form">
<ui:repeat value="#{mrBean.stringList}" var="stringItem">
<h:inputText value="#{stringItem}" />
</ui:repeat>
<h:commandButton value="Add" action="#{mrBean.addContextItem}">
<f:ajax render="@form" execute="@form"></f:ajax>
</h:commandButton>
</h:form>
<h:inputText/>
中输入的表示
stringList
中的字符串的值不被执行。
mrBean.stringList
setter(
setStringList(List<String> stringList)
)。
最佳答案
String
类是不可变的,没有值的 setter 。 setter/getter 基本上是Object#toString()
方法。
您需要直接在List
上获取/设置值。您可以通过<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)
设置该项目。
关于string - 使用<ui :repeat><h:inputText> on a List<String> doesn't update model values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10780858/
我是一名优秀的程序员,十分优秀!