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.

ConverterThatEnforcesAFormat.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package com.vaadin.tests.converter;
  2. import java.util.Locale;
  3. import com.vaadin.server.VaadinRequest;
  4. import com.vaadin.tests.components.AbstractTestUIWithLog;
  5. import com.vaadin.v7.ui.TextField;
  6. public class ConverterThatEnforcesAFormat extends AbstractTestUIWithLog {
  7. @Override
  8. protected void setup(VaadinRequest request) {
  9. final TextField tf = new TextField(
  10. "This field should always be formatted with 3 digits");
  11. tf.setLocale(Locale.ENGLISH);
  12. // this is needed so that IE tests pass
  13. tf.setNullRepresentation("");
  14. tf.setConverter(new StringToDoubleConverterWithThreeFractionDigits());
  15. tf.addValueChangeListener(event -> {
  16. log("Value changed to " + event.getProperty().getValue()
  17. + "(converted value is " + tf.getConvertedValue()
  18. + "). Two-way conversion gives: "
  19. + tf.getConverter().convertToPresentation(
  20. tf.getConverter().convertToModel(tf.getValue(),
  21. Double.class, tf.getLocale()),
  22. String.class, tf.getLocale())
  23. + ")");
  24. });
  25. tf.setImmediate(true);
  26. addComponent(tf);
  27. tf.setConvertedValue(50.0);
  28. }
  29. @Override
  30. protected String getTestDescription() {
  31. return "Entering a valid double in the field should always cause the field contents to be formatted to contain 3 digits after the decimal point";
  32. }
  33. @Override
  34. protected Integer getTicketNumber() {
  35. return 8191;
  36. }
  37. }