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.

IntegerFieldWithoutDataSource.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.vaadin.tests.components.abstractfield;
  2. import com.vaadin.tests.components.TestBase;
  3. import com.vaadin.tests.util.Log;
  4. import com.vaadin.v7.data.Property.ValueChangeListener;
  5. import com.vaadin.v7.ui.TextField;
  6. public class IntegerFieldWithoutDataSource extends TestBase {
  7. private Log log = new Log(5);
  8. @Override
  9. protected void setup() {
  10. addComponent(log);
  11. TextField tf = createIntegerTextField();
  12. tf.setCaption(tf.getCaption() + "(invalid allowed)");
  13. addComponent(tf);
  14. tf = createIntegerTextField();
  15. tf.setInvalidAllowed(false);
  16. tf.setCaption(tf.getCaption() + "(invalid not allowed)");
  17. addComponent(tf);
  18. }
  19. private TextField createIntegerTextField() {
  20. final TextField tf = new TextField("Enter an integer");
  21. tf.setConverter(Integer.class);
  22. tf.setImmediate(true);
  23. tf.addValueChangeListener(event -> {
  24. try {
  25. log.log("Value for " + tf.getCaption() + " changed to "
  26. + tf.getValue());
  27. log.log("Converted value is " + tf.getConvertedValue());
  28. } catch (Exception e) {
  29. // TODO: handle exception
  30. e.printStackTrace();
  31. }
  32. });
  33. return tf;
  34. }
  35. @Override
  36. protected String getDescription() {
  37. // TODO Auto-generated method stub
  38. return null;
  39. }
  40. @Override
  41. protected Integer getTicketNumber() {
  42. // TODO Auto-generated method stub
  43. return null;
  44. }
  45. }