diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2011-11-16 13:17:56 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2011-11-16 13:17:56 +0000 |
commit | 47adbf4e327896791d7adfd7e8c270d524d754ac (patch) | |
tree | e72288602ab22d23fe17fd3ddb9e66a49c8e605c /tests | |
parent | 6719076bfb58ae8b8083512a91f697238680abe1 (diff) | |
download | vaadin-framework-47adbf4e327896791d7adfd7e8c270d524d754ac.tar.gz vaadin-framework-47adbf4e327896791d7adfd7e8c270d524d754ac.zip |
Form and Table now sets property to fields Viewer property if one exists. fixes #7942
svn changeset:22019/svn branch:6.7
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testbench/com/vaadin/tests/components/form/FormWithPropertyFormatterConnected.java | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/testbench/com/vaadin/tests/components/form/FormWithPropertyFormatterConnected.java b/tests/testbench/com/vaadin/tests/components/form/FormWithPropertyFormatterConnected.java new file mode 100644 index 0000000000..116dd5bcc7 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/form/FormWithPropertyFormatterConnected.java @@ -0,0 +1,90 @@ +package com.vaadin.tests.components.form;
+
+import com.vaadin.data.Item;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.data.util.PropertyFormatter;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.AbstractField;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.DefaultFieldFactory;
+import com.vaadin.ui.Field;
+import com.vaadin.ui.Form;
+import com.vaadin.ui.FormFieldFactory;
+
+public class FormWithPropertyFormatterConnected extends TestBase {
+ @Override
+ protected void setup() {
+ Form form2 = new Form();
+ form2.setFormFieldFactory(new FormFieldFactory() {
+
+ public Field createField(Item item, Object propertyId,
+ Component uiContext) {
+ AbstractField f = (AbstractField) DefaultFieldFactory.get()
+ .createField(item, propertyId, uiContext);
+ if (propertyId.equals("age")) {
+ f.setPropertyDataSource(new PropertyFormatter() {
+
+ @Override
+ public Object parse(String formattedValue)
+ throws Exception {
+ String str = formattedValue
+ .replaceAll("[^0-9.]", "");
+ if (formattedValue.toLowerCase().contains("months")) {
+ return Double.parseDouble(str) / 12;
+ }
+ return Double.parseDouble(str);
+ }
+
+ @Override
+ public String format(Object value) {
+ Double dValue = (Double) value;
+ if (dValue < 1) {
+ return ((int)(dValue * 12)) + " months";
+ }
+ return dValue + " years";
+ }
+ });
+ f.setImmediate(true);
+ }
+ return f;
+ }
+ });
+ form2.setItemDataSource(createItem());
+
+ addComponent(form2);
+ addComponent(new Button("B"));
+ }
+
+ private Item createItem() {
+ return new BeanItem<Person>(new Person(0.5));
+ }
+
+ public class Person {
+ public Person(double age) {
+ super();
+ this.age = age;
+ }
+
+ public double getAge() {
+ return age;
+ }
+
+ public void setAge(double age) {
+ this.age = age;
+ }
+
+ private double age;
+ }
+
+ @Override
+ protected String getDescription() {
+ return "It should be possible to inject PropertyFormatter and similar classses to fields in form. The test app hooks formatter that displays age in years or months and also accepts value in both (years by default, months if mentioned in the field)";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return null;
+ }
+
+}
|