final PLabel label1 = new PLabel("Date test");
label1.ensureDebugId("label1");
PRootPanel.get().add(label1);
register(label1);
final PDateBox dateBox1 = new PDateBox(new SimpleDateFormat(datePattern));
dateBox1.ensureDebugId("dateBox1");
PRootPanel.get().add(dateBox1);
register(dateBox1);
}
});
WebElement element = findElementById("dateBox1");
final PDateBox dateBox1 = get("dateBox1");
Assert.assertEquals(datePattern, dateBox1.getDateFormat().toPattern());
// update date
updateUI(new RequestHandler() {
@Override
public void onRequest() {
final PDateBox dateBox1 = get("dateBox1");
dateBox1.setValue(date);
}
});
element = findElementById("dateBox1");
Assert.assertEquals(dateAsString, element.getAttribute("value"));
Assert.assertEquals(dateAsString, dateBox1.getDisplayedValue());
// add value change handler
updateUI(new RequestHandler() {
@SuppressWarnings("unchecked")
@Override
public void onRequest() {
final PDateBox dateBox1 = get("dateBox1");
dateBox1.addValueChangeHandler(eventsListener);
}
});
element = findElementById("dateBox1");
element.clear();
final PValueChangeEvent<Date> e1 = eventsListener.poll();
Assert.assertNull(e1.getValue());
element.click();
element.sendKeys("");
element.sendKeys(new String("2012-10-30"));
element = findElementById("label1");
final Actions actions = new Actions(webDriver);
actions.moveToElement(element).build().perform();
actions.click().build().perform();
final PValueChangeEvent<Date> e2 = eventsListener.poll();
Assert.assertEquals("2012-10-30", dateFormat.format(e2.getValue()));
Assert.assertEquals("2012-10-30", dateBox1.getDisplayedValue());
}