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

Grzegorz.Kluczeka at 2007-7-12 10:26:04 > top of Java-index,Development Tools,Java Tools...
# 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

altairboba at 2007-7-12 10:26:04 > top of Java-index,Development Tools,Java Tools...
# 3
Hi, I think you misunderstood my intentions - this is just an example. I saw that you're setting row header to "Choice" so I assumed that there is such column in your dataprovider. Just set proper column name and this code should work.regardsGrzegorz
Grzegorz.Kluczeka at 2007-7-12 10:26:04 > top of Java-index,Development Tools,Java Tools...
# 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.

altairboba at 2007-7-12 10:26:04 > top of Java-index,Development Tools,Java Tools...
# 5

Hi,

I'm trying to display a DTO (its structure shown below) using the table component. I've bound the table to an ObjectListDataProvider that wraps a list of these DTOs. One of the column shows the listBox component for each row and binds to the "myList" member of the DTO (taken from currentRow as shown in the code snippet below). How can I bind the "myList" to "items" attribute of the listBox without requiring the "MyOtherDTO" class to inherit "com.sun.xxx.rave.Options"? Or is there any other workaround to get the job done?

MyDTO

-key:Integer

-name:String

-myList<MyOtherDTO>:List

<ui:listbox binding="#{Page1.listbox1}" id="listbox1" items="#{currentRow.value['myList']}"/>

Thanks!

b.sodhia at 2007-7-12 10:26:04 > top of Java-index,Development Tools,Java Tools...