javalistgwtdrop-down-menugwtbootstrap3

GWT List Objects


We are currently developing a GWT-App and we need a chooser for People. Problem is that we can't use the names of the people as List items alone, because we have some (unfortunately intended) duplicates in our database. So we need some kind of drop-down list, which allows us to have some kind of ID attached to it. Right now we are using GTW bootstrap3's select, which isn't working out for us because we can only get the String of the selected item back. Any help is appreciated!

EDIT: The best solution for us would be to be able to save objects into the lists and display them via some toString() method or something like that.


Solution

  • You can have an ID and Text in Bootstrap Select. When adding an item to the Select do:

    Option option = new Option();
    option.setValue(ID);
    option.setText(TEXT);
    
    select.add(option);
    

    When you call select.getValue() you will get an ID.

    Option is org.gwtbootstrap3.extras.select.client.ui.Option and both value and text is of type String.