jsf动态输入文本字段

时间:2013-10-17 11:45:41

标签: jsf datatable

我正在创建一个数据表,您可以在其中添加exrta行。在这个额外的行中,有一个输入文本。在输入文本中放入一些内容后,该值应保存到列表中。但事实并非如此。我尝试使用Sting作为参数的下面的方法,但后来保存列表:“javax.faces.component.html.HtmlInputText@23sdf”和类似的东西。当我将方法更改为javax.faces.component.html.HtmlInputText时,方法返回null。

这是表的代码:

    <h:dataTable value="#{correct.newPowody}" var="z" binding="#{table}" >
    <h:inputText binding="#{custom}" value="#{z}">
        <f:ajax event="blur" listener="#{correct.newPowodyAdder(table.rowIndex, custom)}"
                                    execute="@this" render="@form"/>
    </h:inputText>
    </h:dataTable>

这是我正确的bean代码:

    public void newPowodyAdder(int rowIndex, javax.faces.component.html.HtmlInputText powod) {
        String value = powod.getValue().toString();
        this.newPowody.set(rowIndex, value);
    }
}

此方法只需将inputtext中的数据添加到列表中。谢谢你的帮助

1 个答案:

答案 0 :(得分:2)

这段代码真的没有任何意义。这是一个过于复杂的尝试来解决String类不可变的简单问题。不要使用<h:inputText value="#{string}"。只需在EL中使用括号符号[]来引用列表项目,如value="#{bean.strings[index]}"所示:

<h:dataTable binding="#{table}" value="#{correct.newPowody}">
    <h:column>
        <h:inputText value="#{correct.newPowody[table.rowIndex]}" />
    </h:column> 
</h:dataTable>

这就是全部。不需要ajax监听器方法。

另见:

相关问题