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.

ValueThroughProperty.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.vaadin.tests.components.datefield;
  2. import java.util.Calendar;
  3. import java.util.Date;
  4. import java.util.Locale;
  5. import com.vaadin.tests.components.TestBase;
  6. import com.vaadin.ui.Button;
  7. import com.vaadin.ui.Button.ClickEvent;
  8. import com.vaadin.ui.Button.ClickListener;
  9. import com.vaadin.v7.data.Property;
  10. import com.vaadin.v7.data.util.ObjectProperty;
  11. import com.vaadin.v7.shared.ui.label.ContentMode;
  12. import com.vaadin.v7.ui.DateField;
  13. import com.vaadin.v7.ui.Label;
  14. import com.vaadin.v7.ui.PopupDateField;
  15. public class ValueThroughProperty extends TestBase {
  16. private final Property<Date> dateProperty = new ObjectProperty<>(null,
  17. Date.class);
  18. @Override
  19. protected void setup() {
  20. addComponent(new Label(
  21. "Try to input an invalid value to the DateField, for example \"asdf\".<br />"
  22. + "Then try to set DateField's value using the first button. It sets the value "
  23. + "correctly (as we can see from the Label) but the client-side is not updated.<br/>"
  24. + "Using second button updates value correctly on the client-side too.",
  25. ContentMode.XML));
  26. final PopupDateField df = new PopupDateField(dateProperty);
  27. df.setLocale(new Locale("en", "US"));
  28. df.setImmediate(true);
  29. df.setResolution(DateField.RESOLUTION_DAY);
  30. addComponent(df);
  31. Label valueLabel = new Label(df.getPropertyDataSource());
  32. valueLabel.setCaption("DateField's value");
  33. addComponent(valueLabel);
  34. final Calendar cal = Calendar.getInstance();
  35. cal.set(Calendar.YEAR, 2010);
  36. cal.set(Calendar.MONTH, 11);
  37. cal.set(Calendar.DAY_OF_MONTH, 14);
  38. Button setDateButton1 = new Button(
  39. "Set value to 12/14/10 using property", new ClickListener() {
  40. @Override
  41. public void buttonClick(ClickEvent event) {
  42. dateProperty.setValue(cal.getTime());
  43. }
  44. });
  45. addComponent(setDateButton1);
  46. Button setDateButton2 = new Button(
  47. "Set value to 12/14/10 using setValue", new ClickListener() {
  48. @Override
  49. public void buttonClick(ClickEvent event) {
  50. df.setValue(cal.getTime());
  51. }
  52. });
  53. addComponent(setDateButton2);
  54. }
  55. @Override
  56. protected String getDescription() {
  57. return "Setting a value through a property should update the"
  58. + " client-side even if it contains an invalid value.";
  59. }
  60. @Override
  61. protected Integer getTicketNumber() {
  62. return 5810;
  63. }
  64. }