summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Lumme <erik@vaadin.com>2017-09-15 11:51:29 +0300
committerErik Lumme <erik@vaadin.com>2017-09-15 11:51:29 +0300
commit40236881ce54819f1f17a69bf00d776e3a731ac2 (patch)
tree9b6c04624775c949b2626999bd65a82f0dc14192
parentb8c76ef85137d39d05236765dced3ad59844a68e (diff)
downloadvaadin-framework-40236881ce54819f1f17a69bf00d776e3a731ac2.tar.gz
vaadin-framework-40236881ce54819f1f17a69bf00d776e3a731ac2.zip
Migrate AutoGeneratingAFormBasedOnABeanVaadin6StyleForm
-rw-r--r--documentation/articles/AutoGeneratingAFormBasedOnABeanVaadin6StyleForm.asciidoc45
-rw-r--r--documentation/articles/contents.asciidoc1
2 files changed, 46 insertions, 0 deletions
diff --git a/documentation/articles/AutoGeneratingAFormBasedOnABeanVaadin6StyleForm.asciidoc b/documentation/articles/AutoGeneratingAFormBasedOnABeanVaadin6StyleForm.asciidoc
new file mode 100644
index 0000000000..8c4851bfe7
--- /dev/null
+++ b/documentation/articles/AutoGeneratingAFormBasedOnABeanVaadin6StyleForm.asciidoc
@@ -0,0 +1,45 @@
+[[auto-generating-a-form-based-on-a-bean-vaadin-6-style-form]]
+Auto-generating a form based on a bean - Vaadin 6 style Form
+------------------------------------------------------------
+
+In Vaadin 6 it is easy to get a completely auto generated form based on
+a bean instance by creating a `BeanItem` and passing that to a Form. Using
+`FieldGroup` this requires a few extra lines as `FieldGroup` never adds
+fields automatically to any layout but instead gives that control to the
+developer.
+
+Given a bean such as this `Person`:
+
+[source,java]
+....
+public class Person {
+ private String firstName,lastName;
+ private int age;
+ // + setters and getters
+}
+....
+
+You can auto create a form using FieldGroup as follows:
+
+[source,java]
+....
+public class AutoGeneratedFormUI extends UI {
+ @Override
+ public void init(VaadinRequest request) {
+ VerticalLayout layout = new VerticalLayout();
+ setContent(layout);
+
+ FieldGroup fieldGroup = new BeanFieldGroup<Person>(Person.class);
+
+ // We need an item data source before we create the fields to be able to
+ // find the properties, otherwise we have to specify them by hand
+ fieldGroup.setItemDataSource(new BeanItem<Person>(new Person("John", "Doe", 34)));
+
+ // Loop through the properties, build fields for them and add the fields
+ // to this UI
+ for (Object propertyId : fieldGroup.getUnboundPropertyIds()) {
+ layout.addComponent(fieldGroup.buildAndBind(propertyId));
+ }
+ }
+}
+....
diff --git a/documentation/articles/contents.asciidoc b/documentation/articles/contents.asciidoc
index 830c8eeb9f..2f3ce98a50 100644
--- a/documentation/articles/contents.asciidoc
+++ b/documentation/articles/contents.asciidoc
@@ -21,3 +21,4 @@
- link:AddingJPAToTheAddressBookDemo.asciidoc[Adding JPA to the address book demo]
- link:SimplifiedRPCusingJavaScript.asciidoc[Simplified RPC using JavaScript]
- link:JMeterTesting.asciidoc[JMeter testing]
+- link:AutoGeneratingAFormBasedOnABeanVaadin6StyleForm.asciidoc[Auto-generating a form based on a bean - Vaadin 6 style Form]