Can I add JSF components dynamically? I need to have a form with a button which should add one to the form. Is this possible?
I know
Use an iterating component like or to display a dynamically sized List of entities. Make the bean @ViewScoped to ensure that the list is remembered across postbacks on the same view instead of recreated over and over.
Kickoff example with Managed bean: Model: (when using simply replace by , and by e.g. or @Named
@ViewScoped
public class Bean {
private Listpublic 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);
}
}
See also: