Dynamic table with multiple select checkbox

Has anyone managed to implement a dynamic table with a multiple select checkbox component?

My code is based on the dynamic table tutorial: http://developers.sun.com/prodtech/javatools/jscreator/reference/tips/2/createT ableDynamically.html

and the table component sample project from tutorial divas: http://blogs.sun.com/divas/entry/table_component_sample_project

The reason I am using a dynamically created table is because I needed to choose which columns are visible in the table. I achieved this by having a boolean variable in the session bean, and a checkbox on the page for each column, with an update button. When the user presses the button the table is cleared from the grid panel, and a new one is created with the column checkboxes that are checked.

When I select a checkbox in the table the row is highlighted, and the select/deselectMultiple buttons in the table work fine.

I think the problem I have is the checkbox variables 'selected', and ''selectedValue' aren't being set properly.

This is how I dynamically created the checkbox table column:

// Create select column

TableColumn selectRowColumn =new TableColumn();

selectRowColumn.setId("selectRowColumn");

selectRowColumn.setSelectId("selectRowCB");

selectRowColumn.setOnClick("setTimeout('initAllRows()', 0)");

// Add column to table row group

rowGroup.getChildren().add(selectRowColumn);

// Set checkbox

selectRowCB.setId("selectRowCB");

selectRowCB.setSelected(selected);

selectRowCB.setSelectedValue(selectedValue);

// Add the checkbox to the table column

selectRowColumn.getChildren().add(selectRowCB);

The functions I use to handle the selected values are:

private Object selected;

public Object getSelected(){

RowKey rowKey = rowGroup.getRowKey();

info("GET SELECTED: " + rowKey);

return tablePhaseListener.getSelected(rowKey);

}

publicvoid setSelected(Object object){

RowKey rowKey = rowGroup.getRowKey();

info("SET SELECTED: " + rowKey);

if (rowKey !=null){

tablePhaseListener.setSelected(rowKey, object);

}

}

private Object selectedValue;

public Object getSelectedValue(){

RowKey rowKey = rowGroup.getRowKey();

info("SET SELECTEDVALUE: " + rowKey);

return (rowKey !=null) ? rowKey.getRowId() :null;

}

I copied these out of the foodtable tutorial from tutorial divas, and this works fine when the table is created normally. I added some messages to display the rowkey on the page, when each function is called, but nothing is ever shown in the message component.

In order for creator to let me bind the checkbox to these I had to add the following lines:

private Object selected;

private Object selectedValue;

Maybe this is the problem? If i didn't do this creator complained about not being able to find them.

Any thoughts on this would be greatly appreciated, as only have till next friday to complete this project.

Thanks,

Olly

[4117 byte] By [NievO] at [2007-11-26 9:59:24]
# 1

I've figured it out. I now have a fully functional table where I can select which columns are visible, and perform actions on the selected rows.

If anyone needs to know how to do this I could knock up a quick sample project, and mail it to you.

Next to figure out some way of filtering the information in the table.

Olly

NievO at 2007-7-7 1:26:41 > top of Java-index,Development Tools,Java Tools...
# 2
Hello Olly!It could be really useful for me if you could send me that 'quick sample project' you mentioned. I am having the same problem.Thanks in advance!--mono
mono at 2007-7-7 1:26:41 > top of Java-index,Development Tools,Java Tools...
# 3
Could you send me the example code I would very much appreciate it!kburkart21@hotmail.comThanks,Kevin
sheffieldwrigley at 2007-7-7 1:26:41 > top of Java-index,Development Tools,Java Tools...