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.

InputPromptGetText.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.vaadin.tests.components.textfield;
  2. import com.vaadin.annotations.Theme;
  3. import com.vaadin.event.ShortcutAction.KeyCode;
  4. import com.vaadin.event.ShortcutListener;
  5. import com.vaadin.server.VaadinRequest;
  6. import com.vaadin.tests.components.AbstractReindeerTestUI;
  7. import com.vaadin.ui.Button;
  8. import com.vaadin.ui.Label;
  9. import com.vaadin.v7.ui.TextField;
  10. /**
  11. * To verify bug fix: Reproducing of bug Textfield value not updated when
  12. * InputPromt and ShortcutListener are used
  13. *
  14. * #13492
  15. *
  16. * @author Vaadin Ltd
  17. */
  18. @Theme("reindeer")
  19. public class InputPromptGetText extends AbstractReindeerTestUI {
  20. static final String FIELD = "field";
  21. static final String BUTTON = "button";
  22. static final String LABEL1 = "label1";
  23. static final String LABEL2 = "label2";
  24. /*
  25. * (non-Javadoc)
  26. *
  27. * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
  28. * VaadinRequest)
  29. */
  30. @Override
  31. protected void setup(VaadinRequest request) {
  32. final TextField tf = new TextField();
  33. tf.setId(FIELD);
  34. tf.setInputPrompt("input text here");
  35. tf.setImmediate(true);
  36. tf.setNullRepresentation("");
  37. Button button = new Button("Click Me");
  38. button.setId(BUTTON);
  39. button.addClickListener(event -> {
  40. String input = tf.getValue();
  41. Label label = new Label("Your input was: " + input);
  42. label.setId(LABEL2);
  43. getLayout().addComponent(label);
  44. });
  45. tf.addShortcutListener(
  46. new ShortcutListener("Shortcut", KeyCode.ENTER, null) {
  47. @Override
  48. public void handleAction(Object sender, Object target) {
  49. String input = tf.getValue();
  50. Label label = new Label("Your input was: " + input);
  51. label.setId(LABEL1);
  52. getLayout().addComponent(label);
  53. }
  54. });
  55. getLayout().addComponent(tf);
  56. getLayout().addComponent(button);
  57. }
  58. @Override
  59. protected String getTestDescription() {
  60. return "Reproducing of bug Textfield value not updated when InputPromt and ShortcutListener are used";
  61. }
  62. @Override
  63. protected Integer getTicketNumber() {
  64. return 13492;
  65. }
  66. }