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.

DateTimeFieldIsValid.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.vaadin.tests.components.datefield;
  2. import java.time.LocalDateTime;
  3. import java.time.format.DateTimeFormatter;
  4. import com.vaadin.server.VaadinRequest;
  5. import com.vaadin.tests.components.AbstractTestUIWithLog;
  6. import com.vaadin.ui.DateTimeField;
  7. public class DateTimeFieldIsValid extends AbstractTestUIWithLog {
  8. @Override
  9. protected String getTestDescription() {
  10. return "A dateField with invalid text should return false in isValid both when "
  11. + "handling ValueChange event and after value is changed.";
  12. }
  13. @Override
  14. protected Integer getTicketNumber() {
  15. return 14487;
  16. }
  17. private String pattern = "dd/MM/yy H.mm";
  18. private DateTimeFormatter format = DateTimeFormatter.ofPattern(pattern);
  19. @Override
  20. protected void setup(VaadinRequest request) {
  21. final DateTimeField dateField = new DateTimeField("Insert Date: ");
  22. dateField.setDateFormat(pattern);
  23. dateField.addValueChangeListener(event -> log("valueChange: value: "
  24. + format(dateField.getValue()) + ", is valid: "
  25. + (dateField.getErrorMessage() == null)));
  26. addComponent(dateField);
  27. addButton("check dateField",
  28. event -> log("buttonClick: value: "
  29. + format(dateField.getValue()) + ", is valid: "
  30. + (dateField.getErrorMessage() == null)));
  31. }
  32. protected String format(LocalDateTime value) {
  33. if (value != null) {
  34. return format.format(value);
  35. } else {
  36. return null;
  37. }
  38. }
  39. }