Access a drop down list from a dynamic table.
I have created a dynamic table from a database and have added a drop down list to a column in the table as well as a button in the next column.
TableColumn tableColumn3 =new TableColumn();
int colCount3 = rowGroup.getChildCount();
tableColumn3.setId("tableColumn"+colCount3);
tableColumn3.setHeaderText("Choice");
// Add the fourth table Column to the table row group
rowGroup.getChildren().add(tableColumn3);
DropDown choice =new DropDown();
choice.setItems(vals);
tableColumn3.getChildren().add(choice);
Any ideas on how I can get the current value in the drop down list from the button's click action?
I'm thinking maybe when I create the dropDown somesort of binding needs to be done perhaps, since the table is created at runtime and the dropDown doesn't exist yet.
Hence I can't use dropDown1.getSelected();
[1079 byte] By [
altairboba] at [2007-11-27 5:07:05]

# 1
Hi,
I assume that your table is bound to a data provider and sourceVar property of TableRowGroup is set to "currentRow". You should modify your code to look like this:
TableColumn tableColumn3 = new TableColumn();
int colCount3 = rowGroup.getChildCount();
tableColumn3.setId("tableColumn"+colCount3);
tableColumn3.setHeaderText("Choice");
// Add the fourth table Column to the table row group
rowGroup.getChildren().add(tableColumn3);
DropDown choice = new DropDown();
choice.setItems(vals);
//create value binding
choice.setValueBinding("selected", getApplication().createValueBinding("#{currentRow.value['CHOICE']}"));
tableColumn3.getChildren().add(choice);
Now in your button click action you can retrieve selected value:
private String button1_action() {
//..
Object dropDownValue = getValue("#{currentRow.value['CHOICE']}");
//..
}
regards
Grzegorz
# 2
Thank you for the prompt reply.
The setValueBinding causes the following exception for some reason?
Exception Details: java.lang.IllegalArgumentException
CHOICE
Possible Source of Error:
Class Name: com.sun.data.provider.impl.CachedRowSetDataProvider
File Name: CachedRowSetDataProvider.java
Method Name: getFieldKeyInternal
Line Number: 481
I take it this means there's a problem with binding to the ['CHOICE'] value?
Thanks in advance altairbob
# 4
Ah, there isn't a Choice column in the dataprovider, the intention of the dropDown was to select as an option one of the column headers.
I believe what I am trying to do isn't possible, I have managed to populate the dropDown with the desired values. But the dropDown seems to be unreachable once the table has been created dynamically.
I think I'll have to find another way to incorporate the functionality I desire.
Thank you for your help though.