Adding form elements dynamically upon user action

Hi All,I have a page in which user enters a set of values (eg., dependant details). I want to have an "Add Row" button to generate the similar set of form elements (to input another dependant detail). How do I generate these form elements and binding it to the backing bean data?
[293 byte] By [eegaia] at [2007-11-26 23:44:06]
# 1

Use h:dataTable and DTO's.

JSF<h:dataTable value="#{myBean.list}" var="item">

<h:column><h:inputText value="#{item.value1}" /></h:column>

<h:column><h:inputText value="#{item.value2}" /></h:column>

<h:column><h:inputText value="#{item.value3}" /></h:column>

</h:dataTable>

<h:commandButton value="add" action="#{myBean.add}" />

MyBeanprivate List<Dto> list; // + getter + setter

public void add() {

list.add(new Dto());

}

DTOpublic class Dto() {

private String value1;

private String value2;

private String value3;

// + getters + setters

}

This article might give you some new insights about using datatables, also note the CRUD example in the downloadable EAR there: http://balusc.xs4all.nl/srv/dev-jep-dat.html

BalusCa at 2007-7-11 15:15:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...