Reputation: 113
I have a list of name with its unique ID, I use NativeSelect to make drop down list of the name. However, I don't know how to set the option value with the unique ID. So it could display the name on the drop down list, but the value of the option was unique ID. How can I set option value with unique ID since NativeSelect set 1
, 2
, 3
and etc. as option value by default ?
final NativeSelect nameSelect = new NativeSelect();
List<String> nameList= getNameList();
nameSelect.setRequired(true);
nameSelect.setRequiredError("Please select the name !");
for(String s: nameList){
//uniqueID~personName
String[] person = s.split("~");
nameSelect.addItem(person[1]);
}
Upvotes: 0
Views: 200
Reputation: 4754
Please read the corresponding section in the book of vaadin.
Basically you can set the caption of the items you add to the select component.
final NativeSelect nameSelect = new NativeSelect();
List<String> nameList= getNameList();
nameSelect.setRequired(true);
nameSelect.setRequiredError("Please select the name !");
for(String s: nameList){
//uniqueID~personName
String[] person = s.split("~");
nameSelect.addItem(person[0]);
nameSelect.setItemCaption(person[0], person[1]);
}
Upvotes: 1