You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NativeSelectSetValue.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.vaadin.tests.elements.nativeselect;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import com.vaadin.data.provider.ListDataProvider;
  5. import com.vaadin.event.selection.SingleSelectionEvent;
  6. import com.vaadin.event.selection.SingleSelectionListener;
  7. import com.vaadin.server.VaadinRequest;
  8. import com.vaadin.tests.components.AbstractTestUI;
  9. import com.vaadin.ui.Label;
  10. import com.vaadin.ui.NativeSelect;
  11. public class NativeSelectSetValue extends AbstractTestUI {
  12. private int counter = 0;
  13. Label lblCounter = new Label("0");
  14. @Override
  15. protected void setup(VaadinRequest request) {
  16. NativeSelect select = new NativeSelect();
  17. List<String> options = new ArrayList<>();
  18. options.add("item 1");
  19. options.add("item 2");
  20. options.add("item 3");
  21. select.setDataProvider(new ListDataProvider<>(options));
  22. select.setValue("item 1");
  23. lblCounter.setId("counter");
  24. select.addSelectionListener(new EventCounter());
  25. addComponent(select);
  26. addComponent(lblCounter);
  27. }
  28. private class EventCounter implements SingleSelectionListener<String> {
  29. private int counter = 0;
  30. @Override
  31. public void selectionChange(SingleSelectionEvent<String> event) {
  32. counter++;
  33. lblCounter.setValue("" + counter);
  34. }
  35. }
  36. @Override
  37. protected String getTestDescription() {
  38. return "Native select element setValue method should change value and triggers change event";
  39. }
  40. @Override
  41. protected Integer getTicketNumber() {
  42. return 13365;
  43. }
  44. }