gpt4 book ai didi

string - 使用 on a List doesn't update model values

转载 作者:行者123 更新时间:2023-12-03 15:57:16 27 4
gpt4 key购买 nike

这是场景(简化):

有一个具有成员和适当的getter/setter的bean(称为mrBean):

private List<String> rootContext;

public void addContextItem() {
rootContext.add("");
}

JSF代码:
<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))。

知道为什么吗?

一些信息-
我在Tomcat 6上使用MyFaces JSF 2.0。

最佳答案

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com