Use a h:dataTable
to display a dynamically sized collection of items.
JSF kickoff example:
<h:form>
<h:dataTable value="#{bean.items}" var="item">
<h:column><h:inputText value="#{item.value}" /></h:column>
</h:dataTable>
<h:commandButton value="add" action="#{bean.add}" />
<h:commandButton value="submit" action="#{bean.submit}" />
</h:form>
Bean
class:
@ManagedBean
@ViewScoped
public class Bean {
private List<Item> items = new ArrayList<Item>();
public void add() {
items.add(new Item());
}
public void submit() {
System.out.println("items: " + items);
}
public List<Item> getItems() {
return items;
}
}
Item
class:
public class Item {
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String toString() {
return String.format("Item[value=%s]", value);
}
}