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.

NativeSelectCaptionGeneration.java 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package com.vaadin.tests.components.nativeselect;
  2. import com.vaadin.annotations.DesignRoot;
  3. import com.vaadin.server.VaadinRequest;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.ui.HorizontalLayout;
  6. import com.vaadin.ui.ItemCaptionGenerator;
  7. import com.vaadin.ui.NativeSelect;
  8. import com.vaadin.ui.UI;
  9. import com.vaadin.ui.VerticalLayout;
  10. import com.vaadin.ui.declarative.Design;
  11. public class NativeSelectCaptionGeneration extends UI {
  12. @DesignRoot
  13. public static class TestComponent extends VerticalLayout {
  14. HorizontalLayout buttons;
  15. NativeSelect<String> nativeSelect;
  16. public TestComponent() {
  17. Design.read(this);
  18. // Store the declarative with to string fallback
  19. ItemCaptionGenerator<String> declarative = nativeSelect
  20. .getItemCaptionGenerator();
  21. buttons.addComponents(
  22. new Button("toString",
  23. event -> nativeSelect
  24. .setItemCaptionGenerator(String::toString)),
  25. new Button("Only number",
  26. event -> nativeSelect.setItemCaptionGenerator(
  27. str -> str.substring(7))),
  28. new Button("Declarative", event -> nativeSelect
  29. .setItemCaptionGenerator(declarative)));
  30. }
  31. }
  32. @Override
  33. protected void init(VaadinRequest request) {
  34. setContent(new TestComponent());
  35. }
  36. }