Editable dynamic tables

Hello all,

I am developing an application using dynamic tables using the method detailed in the tutorial "Dynamically Creating a Table Component in Sun Java Studio Creator 2" at the site

http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/createTableDynamically.html

The table is properly shown in the page, but I would like to enable the user to edit the rows in the table and to add new rows and delete rows. To delete the rows is not a problem as such, since I can find the id of the row and delete it manually in the database, but I am unable to recover the new data that is given by the user in the table. It seems to me like the data provider never is updated with the new data, since I only ever manage to access the old data.

Any comments on this would be greatly appreciated.

Thank you in advance

Erik

[877 byte] By [Uthoriona] at [2007-11-26 13:00:16]
# 1
You just want a CRUD datatable?Check http://balusc.xs4all.nl/srv/dev-jep-dat.html how to use datatables.At the bottom there is a download link with a CRUD datatable example.
BalusCa at 2007-7-7 17:00:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thank you for you response. In fact I want a dynamically generated data table (such as the example "Dynamically populate datatable" at the bottom of the page you gave). Here is an excerpt of my code :

#### CODE

//Create the Table Dynamically

Table table = new Table();

table.setId("table1");

table.setTitle(tableConfig.getLibelle());

table.setPaginateButton(true);

table.setPaginationControls(true);

// Create the Table Row group dynamically

TableRowGroup rowGroup = new TableRowGroup();

rowGroup.setId("rowGroup1");

rowGroup.setSourceVar("currentRow");

rowGroup.setValueBinding("sourceData", getApplication().

createValueBinding("#{TableConfigPage.dynamiqueTableDataProvider}"));

rowGroup.setRows(10);

// Add the table row group to the table as a child

table.getChildren().add(rowGroup);

//Iterate over the columns

Iterator<ColumnConfig> colonnes = tableConfig.getColonnes().iterator();

while(colonnes.hasNext()){

ColumnConfig c = colonnes.next();

// Create the table Column

TableColumn tableColumn1 = new TableColumn();

tableColumn1.setId("tableColumn"+c.getName());

tableColumn1.setHeaderText(c.getLibelle());

tableColumn1.setVisible(c.isVisible());

// Add the table Column to the table row group

rowGroup.getChildren().add(tableColumn1);

// Create the Static text and set its value as TRIPID

if(c.getType().equalsIgnoreCase("boolean")){

String ref = "";

if(c.getTableRefObject() == null){

ref = c.getName();

}else{

ref = c.getTableRefObject().getDisplayColumn();

}

tableColumn1.setSort(ref);

Checkbox checkBox1 = new Checkbox();

checkBox1.setValueBinding("selected", getApplication().

createValueBinding("#{currentRow.value['"+ref+"']!='0'}"));

checkBox1.setValueBinding("disabled", getApplication().

createValueBinding("#{currentRow.value['"+key+"'] ne SessionBean1.modifiableRow}"));

// Add the CheckBox to the table column1

tableColumn1.getChildren().add(checkBox1);

}else if(c.getType().equalsIgnoreCase("DropDown") && c.getTableRefObject() != null){

String ref = c.getName();

DropDown dropDown1 = new DropDown();

ConnectionManager cm = WebConnectionManager.get();

PreparedStatement ps = cm.getConnection().prepareStatement(c.getReferenceSelectRequete());

ResultSet rs = ps.executeQuery();

ArrayList<Option> options = new ArrayList();

while(rs.next()){

options.add(new Option(rs.getBigDecimal(1), rs.getString(2)));

}

if(options.size() > 0){

Option[] optionsArray = new Option[options.size()];

optionsArray = options.toArray(optionsArray);

dropDown1.setItems(optionsArray);

}

dropDown1.setValueBinding("selected", getApplication().

createValueBinding("#{currentRow.value['"+ref+"']}"));

dropDown1.setValueBinding("disabled", getApplication().

createValueBinding("#{currentRow.value['"+key+"'] ne SessionBean1.modifiableRow}"));

// Add the DropDown to the table column1

tableColumn1.getChildren().add(dropDown1);

//dropDown1.setDisabled(true);

}else{

String ref = "";

if(c.getTableRefObject() == null){

ref = c.getName();

}else{

ref = c.getTableRefObject().getDisplayColumn();

}

TextField textField1 = new TextField();

//ValueExpression ve = getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),"#{currentRow.value['"+ref+"']}", String.class);

//textField1.setValueExpression("text", ve);

textField1.setValueBinding("text", getApplication().

createValueBinding("#{currentRow.value['"+ref+"']}"));

textField1.setValueBinding("disabled", getApplication().

createValueBinding("#{currentRow.value['"+key+"'] ne SessionBean1.modifiableRow}"));

//textField1.setDisabled(true);

// Add the TextField to the table column1

tableColumn1.getChildren().add(textField1);

}

}

// Create the table Column

TableColumn modifierTableColumn = new TableColumn();

modifierTableColumn.setId("modifierColumn");

modifierTableColumn.setHeaderText("");

modifierTableColumn.setAlign("center");

// Add the table Column to the table row group

rowGroup.getChildren().add(modifierTableColumn);

// Create the Button and set its value as TRIPID

Button modifierButton = new Button();

modifierButton.setValueBinding("text", getApplication().

createValueBinding("#{currentRow.value['"+key+"'] ne SessionBean1.modifiableRow ? 'Modifier' : 'Sauver'}"));

modifierButton.setAction(getApplication().createMethodBinding("#{TableConfigPage.modifierButton_action}", null));

modifierButton.setId("modifierButton");

modifierTableColumn.getChildren().add(modifierButton);

// Create the table Column

TableColumn supprimerTableColumn = new TableColumn();

supprimerTableColumn.setId("supprimerColumn");

supprimerTableColumn.setHeaderText("");

supprimerTableColumn.setAlign("center");

// Add the table Column to the table row group

rowGroup.getChildren().add(supprimerTableColumn);

// Create the Button and set its value as TRIPID

Button supprimerButton = new Button();

supprimerButton.setValueBinding("text", getApplication().

createValueBinding("#{currentRow.value['"+key+"'] ne SessionBean1.modifiableRow ? 'Supprimer' : 'Annuler'}"));

supprimerButton.setAction(getApplication().createMethodBinding("#{TableConfigPage.supprimerButton_action}", null));

supprimerButton.setId("supprimerButton");

supprimerTableColumn.getChildren().add(supprimerButton);

if(rowAdded){

rowAdded = false;

}

tableGridPanel.getChildren().add(table);

#### CODE

The data provider is configured dynamically as well, based on an XML file which contains the definition of the different tables to be used. My problem is that the user should be able to edit the data, select a row in the dropdowns and so on, but during the postback the new data is not propagated to the data provider.

I hope this will clarify a bit my problem, I have not found anything on the web which could help me with this, so any help would be appreciated.

Thank you.

Uthoriona at 2007-7-7 17:00:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Did anybody made dynamicaly created editable table ?Thans for response.
AndriusViska at 2007-7-7 17:00:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...