我能够呈现动态但不知道如何在后端获取那些动态创建的值。
测试.xhtml
<h:form>
Insert Your Desire Number : <h:inputText value="#{bean.number}">
<f:ajax listener="#{bean.submitAjax}" execute="@form" render="@form" event="keyup" />
</h:inputText>
<br></br>
<h:outputText value="#{bean.text}" />
<h:dataTable value="#{bean.items}" var="item">
<h:column>
<h:inputText value="#{item.value}" />
</h:column>
</h:dataTable>
<h:commandButton value="Submit" action="#{item.submit}" />
</h:form>
如果我渲染 3 个输入框,并且当我提交按钮时,我只得到最后一个值,有人可以指导我怎么做
Bean.java
@ManagedBean(name="bean")
@SessionScoped
public class Bean {
private int number;
private List<Item> items;
private Item item;
//getter and setter are omitted
public void submitAjax(AjaxBehaviorEvent event)
{
items = new ArrayList<Item>();
for (int i = 0; i < number; i++) {
items.add(new Item());
}
}
}
项目.java
private String value;
//getter and setter are omitted
public void submit() {
System.out.println("Form Value : "+value);
}