@Override
protected void setup() {
/*
* Create and configure form.
*/
final Form form = new Form();
form.setBuffered(true); // set write buffering on
form.setImmediate(true); // make form (and especially its fields
// immediate)
/*
* Create and configure Date Field, the actual component to be tested.
*/
dateProperty = new ObjectProperty<Date>(new Date(2009 - 1900, 4 - 1, 1));
dateField = new DateField("Year", dateProperty);
dateField.setLocale(new Locale("fi", "FI"));
dateField.setResolution(DateField.RESOLUTION_DAY);
dateField.setId("_DF");
form.addField("date", dateField);
/*
* Create a TextField with integer property (and integer validator,
* preventing invalid typed values to be pushded to property) as a
* reference component.
*/
integerProperty = new ObjectProperty<Integer>(42);
integerField = new TextField("Another Field", integerProperty);
integerField.setId("_IF");
form.addField("text", integerField);
/*
* Action buttons.
*/
Button validate = new Button("Validate");
validate.setId("_validate");
validate.addListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
try {
form.validate();
log.log("Form is valid");
} catch (InvalidValueException e) {
log.log("Validation failed:" + e.getLocalizedMessage());
} finally {
printState();
}
}
});
form.getFooter().addComponent(validate);
Button commit = new Button("Commit");
commit.setId("_commit");
commit.addListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
try {
form.commit();
log.log("Commit succeeded");
} catch (InvalidValueException e) {
log.log("Commit failed : " + e.getLocalizedMessage());
} finally {
printState();
}
}
});
form.getFooter().addComponent(commit);
Button printState = new Button("printState");
printState.addListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
printState();
}
});
form.getFooter().addComponent(printState);
log = new Log(7);
log.log("Test app started");
printState();