package com.vaadin.tests.minitutorials;
-import com.vaadin.data.Item;
-import com.vaadin.data.fieldgroup.Caption;
import com.vaadin.data.fieldgroup.FieldGroup;
import com.vaadin.data.fieldgroup.PropertyId;
import com.vaadin.data.util.BeanItem;
}
public static class MyFormLayout extends GridLayout {
- private TextField firstName;
- private TextField lastName;
+ private TextField firstName = new TextField("First name");
+ private TextField lastName = new TextField("Last name");
// The name of the property is by default the name of the member field,
// but it can be redefined with the @PropertyId annotation
@PropertyId("message")
- // The field caption is by default derived from the property id, but can
- // be redefined with the @Caption annotation
- @Caption("Your message")
- private TextArea messageField;
+ private TextArea messageField = new TextArea("Your message");
- public MyFormLayout(Item item) {
+ public MyFormLayout() {
// Set up the GridLayout
super(2, 3);
setSpacing(true);
- // Create a field group
- final FieldGroup fieldGroup = new FieldGroup(item);
-
- // Create and bind fields for the item and inject the fields to this
- fieldGroup.buildAndBindMemberFields(this);
-
- // The fields have been initialized and can be added to the layout
+ // Add the (currently unbound) fields
addComponent(firstName);
addComponent(lastName);
@Override
protected void setup(WrappedRequest request) {
- addComponent(new MyFormLayout(new BeanItem<Notice>(new Notice("John",
- "Doe", ""))));
+ // Create the layout
+ MyFormLayout myFormLayout = new MyFormLayout();
+
+ // Create a field group and use it to bind the fields in the layout
+ FieldGroup fieldGroup = new FieldGroup(new BeanItem<Notice>(new Notice(
+ "John", "Doe", "")));
+ fieldGroup.bindMemberFields(myFormLayout);
+
+ addComponent(myFormLayout);
}
@Override