From 43184719496a21d6d8c2d8c1dc9524b180893892 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Mon, 2 Jan 2012 15:52:37 +0200 Subject: [PATCH] Updated mini tutorial to use precreated fields --- .../FormUsingExistingLayout.java | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/tests/testbench/com/vaadin/tests/minitutorials/FormUsingExistingLayout.java b/tests/testbench/com/vaadin/tests/minitutorials/FormUsingExistingLayout.java index 8ab2dafb30..9d20867d24 100644 --- a/tests/testbench/com/vaadin/tests/minitutorials/FormUsingExistingLayout.java +++ b/tests/testbench/com/vaadin/tests/minitutorials/FormUsingExistingLayout.java @@ -1,7 +1,5 @@ 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; @@ -51,29 +49,20 @@ public class FormUsingExistingLayout extends AbstractTestRoot { } 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); @@ -85,8 +74,15 @@ public class FormUsingExistingLayout extends AbstractTestRoot { @Override protected void setup(WrappedRequest request) { - addComponent(new MyFormLayout(new BeanItem(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(new Notice( + "John", "Doe", ""))); + fieldGroup.bindMemberFields(myFormLayout); + + addComponent(myFormLayout); } @Override -- 2.39.5