// Create form for editing address
final Form f = new Form();
f.setItemDataSource(new BeanItem<Address>(address, new String[] {
"name", "street", "zip", "city", "state", "country" }));
f.setCaption("Office address");
f.setIcon(new ThemeResource("../runo/icons/16/document.png"));
f.setDescription("Jep jpe, this is form description.");
mainWin.addComponent(f);
// Select to use buffered mode for editing to enable commit and discard
f.setBuffered(true);
Button commit = new Button("Commit", new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
f.commit();
}
});
Button discard = new Button("Discard", new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
f.discard();
}
});
HorizontalLayout ol = new HorizontalLayout();
ol.setHeight("3em");
ol.addComponent(commit);
ol.setComponentAlignment(commit, Alignment.TOP_RIGHT);
ol.addComponent(discard);
f.setFooter(ol);
// Add some validators for the form
f.getField("zip").addValidator(
new IntegerValidator("'{0}' is not a number"));
((AbstractComponent) f.getField("zip")).setDescription("Jepjep");
((AbstractComponent) f.getField("zip")).setIcon(new ThemeResource(
"../runo/icons/16/folder.png"));
f.getField("state").addValidator(new IsValidState());
f.getField("name").setRequired(true);
f.getField("street").setRequired(true);
f.getField("city").setRequired(true);