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.

TextFieldValueGoesMissing.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.vaadin.tests.components.table;
  2. import com.vaadin.server.VaadinRequest;
  3. import com.vaadin.tests.components.AbstractTestUI;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.ui.Button.ClickEvent;
  6. import com.vaadin.ui.Label;
  7. import com.vaadin.ui.Table;
  8. import com.vaadin.ui.TextField;
  9. import com.vaadin.ui.VerticalLayout;
  10. public class TextFieldValueGoesMissing extends AbstractTestUI {
  11. @SuppressWarnings("unchecked")
  12. @Override
  13. protected void setup(VaadinRequest request) {
  14. final VerticalLayout verticalLayout = new VerticalLayout();
  15. final Label label1 = new Label("1");
  16. final Label label2 = new Label("2");
  17. Button button = new Button("Replace label");
  18. button.addClickListener(new Button.ClickListener() {
  19. @Override
  20. public void buttonClick(ClickEvent event) {
  21. if (verticalLayout.getComponentIndex(label1) > -1) {
  22. verticalLayout.replaceComponent(label1, label2);
  23. } else {
  24. verticalLayout.replaceComponent(label2, label1);
  25. }
  26. }
  27. });
  28. verticalLayout.addComponent(button);
  29. verticalLayout.addComponent(label1);
  30. Table table = new Table();
  31. table.addContainerProperty("Field", TextField.class, null);
  32. Object id = table.addItem();
  33. TextField tf = new TextField();
  34. table.getItem(id).getItemProperty("Field").setValue(tf);
  35. verticalLayout.addComponent(table);
  36. addComponent(verticalLayout);
  37. }
  38. @Override
  39. protected String getTestDescription() {
  40. return "Enter a text in the TextField in the table and press the 'Replace label' button. This replaces the label which is in the same layout as the table but should not cause the TextField in the table to lose its contents";
  41. }
  42. @Override
  43. protected Integer getTicketNumber() {
  44. return 6902;
  45. }
  46. }