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.

ComboBoxReapperingOldValue.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package com.vaadin.tests.components.combobox;
  2. import com.vaadin.server.LegacyApplication;
  3. import com.vaadin.ui.Label;
  4. import com.vaadin.ui.LegacyWindow;
  5. import com.vaadin.ui.VerticalLayout;
  6. import com.vaadin.v7.data.Container;
  7. import com.vaadin.v7.data.Property.ValueChangeEvent;
  8. import com.vaadin.v7.data.Property.ValueChangeListener;
  9. import com.vaadin.v7.data.util.IndexedContainer;
  10. import com.vaadin.v7.shared.ui.combobox.FilteringMode;
  11. import com.vaadin.v7.ui.ComboBox;
  12. @SuppressWarnings("serial")
  13. public class ComboBoxReapperingOldValue extends LegacyApplication
  14. implements ValueChangeListener {
  15. ComboBox cbox1 = new ComboBox();
  16. ComboBox cbox2 = new ComboBox();
  17. @Override
  18. public void init() {
  19. LegacyWindow mainWindow = new LegacyWindow("ComboBoxCacheTest");
  20. setMainWindow(mainWindow);
  21. VerticalLayout layout = new VerticalLayout();
  22. Label lbl = new Label(
  23. "try selecting value 1 from the first combo box, so that the second combo box will be populated. select a value in second combo box."
  24. + "then select a new value from combo box one, after that click on the second combo box. The old selected value appears.");
  25. layout.addComponent(lbl);
  26. cbox1.setCaption("Com Box 1");
  27. cbox1.setFilteringMode(FilteringMode.CONTAINS);
  28. cbox1.setContainerDataSource(getContainer());
  29. cbox1.setImmediate(true);
  30. cbox1.setNullSelectionAllowed(false);
  31. cbox1.addListener(this);
  32. layout.addComponent(cbox1);
  33. layout.addComponent(cbox2);
  34. cbox2.setCaption("Com Box 2");
  35. cbox2.setEnabled(false);
  36. cbox2.setNullSelectionAllowed(false);
  37. mainWindow.setContent(layout);
  38. }
  39. private Container getContainer() {
  40. IndexedContainer container = new IndexedContainer();
  41. container.addContainerProperty("na", String.class, null);
  42. for (int i = 0; i < 10; i++) {
  43. container.addItem(i);
  44. }
  45. return container;
  46. }
  47. @Override
  48. public void valueChange(ValueChangeEvent event) {
  49. cbox2.removeAllItems();
  50. if ("1".equals(event.getProperty().getValue().toString())) {
  51. cbox2.setEnabled(true);
  52. cbox2.setContainerDataSource(getContainer());
  53. }
  54. }
  55. }