cancel
Showing results for 
Search instead for 
Did you mean: 

DropdownListBox

former_member271246
Participant
0 Kudos

When trying to get the text value of my DropdownListBox using the key, it returns null. I can out the key value fine. Look at my code.

DropdownListBox lb = (DropdownListBox).getComponentByName("Roles");

key = lb.getSelection();

String keyText = lb.getTextForKey(key);

response.write(keyText);

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Try this code:

DropdownListBox lb = (DropdownListBox)this.getComponentByName("Roles");

key = lb.getSingleSelection();

String keyText = lb.getTextForKey(key);

response.write(keyText);

Let me know the result.

Regards

Yoga

former_member271246
Participant
0 Kudos

What class is getSingleSelection() define too? Cannot be found in standard htmlb classes.

Former Member
0 Kudos

hi william,

I dont think getSingleSelection() shhould work fine. Dropdown listbox has to be associated with IListModel as it stores multiple values.

dropdownlist stores the values and relates it with the key, we are first getting the key for the selected item. Then we are getting the particular value from the default list model, by which it is actually stored .

Regards,

Ganesh N

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi William,

This works fine for me...

DropdownListBox list =(DropdownListBox)this.getComponentByName(event.getComponentName());

String newKey =list.getSelection();

DefaultListModel dListModel=(DefaultListModel)bean.getModel();

String selectedText = dListModel.getTextForKey(newKey);

Regards,

Karthick

Former Member
0 Kudos

hi,

See this thread for more information

Regards,

Ganesh N

Former Member
0 Kudos

Hi,

I think the method you adapted always returns null,

even I tried this but in vain.It may be the problem

with dropdownlistbox control.

Alternately the following method solves the purpose

DropdownListBox lb = (DropdownListBox) getComponentByName("Roles");
if (lb != null) 
{
String keyText = lb.getSelection();
}

Only thing we have to do is key and value should be the same while adding items in dropdownlistbox.

i.e.,lb.addItem("item1","item1");

Rgds,

Santhosh