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

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

这是场景(简化):

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

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.stringListsetter(setStringList(List<String> stringList))。

知道为什么吗?

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


宝慕林4294392
浏览 593回答 1
1回答

繁星coding

该String班是不可改变的,不具有该值的制定者。吸气剂基本上就是Object#toString()方法。您需要直接获取/设置值List。您可以通过列表索引执行此操作<ui:repeat varStatus>。<ui:repeat&nbsp;value="#{mrBean.stringList}"&nbsp;varStatus="loop"> &nbsp;&nbsp;&nbsp;&nbsp;<h:inputText&nbsp;value="#{mrBean.stringList[loop.index]}"&nbsp;/></ui:repeat>你不需要一个setter&nbsp;stringList。EL将获取该项目List#get(index)并设置项目List#add(index,item)。
打开App,查看更多内容
随时随地看视频慕课网APP