Dynamically add component to a table

Hi all, I am trying to create a table for data entry where user should be able to enter data into multiple textfield. Problem is after I created the columns dynamically, the Table shows only one textfield instead of multiples. here is the sample code…

String testString = new String {testColumn1, testColumn2, testColumn3};
Table testTable = new Table();
for(int i = 0; i < testString.length; i++)
, TextField.class, null);
TextField tf = new TextFiled();
testTable.addItem(new Object {tf}, i);

above code did produce a table with three columns but one textfiled, not three… can someone help?

If you want multiple textfields in a table I do it that way:

Table table = new Table();
table.addContainerProperty(“Textfield1”, TextField.class, null);
table.addContainerProperty(“Textfield2”, TextField.class, null);

List data = someDate
for(String text : data) {
TextField textField1 = new TextField();
TextField textField2 = new TextField();
table.addItem(new Object {
textField2}, text};
[/code]Now two textfields are displayed in the table.


Florian, thanks for the reply. I am trying to create textfield in a table dynamically as my list of column can grow.

Okay in this case you will have to realize this in some kind of that way:

You will have ti implement a dynmaic object e.g.

public class MyDynamicObject {
private String name;
private List textFields;

// Getter an setter methods
[/code]Next you will have to create a table, someway like that:

Table table = new Table();

List<MyDynamicObject> objects; // contains the objects which should be displayed
for(MyDynamicObject object : objects) {
  List<TextFields> textfields = object.getTextFields();
  // inner loop to create the container properties
  for(TextField textField : textfields) {
    table.addContainerProperty("Textfield1", TextField.class, null);

  // finally create an object which contains the data
  Object[] tableObject = new Object[1+textFields.getSize()]

  // fill the tableObject
  for(int i=0; i<tableObject.length; i++) {
    if(i == 0)
 = object.getName();
 = textFields.get(i-1); // The textfield list also starts at 0, but on position 0 of the array we have the name

  // finally add the object to the table
  table.addItem(tableObject, object);

This code is not tested but it should work in that way.