package com.vaadin.data.fieldbinder;\r
\r
import com.vaadin.data.Item;\r
-import com.vaadin.data.Property;\r
import com.vaadin.data.util.BeanItem;\r
-import com.vaadin.data.util.NestedMethodProperty;\r
import com.vaadin.data.validator.BeanValidationValidator;\r
import com.vaadin.ui.Field;\r
\r
}\r
}\r
\r
+ /**\r
+ * Helper method for setting the data source directly using a bean. This\r
+ * method wraps the bean in a {@link BeanItem} and calls\r
+ * {@link #setItemDataSource(Item)}.\r
+ * \r
+ * @param bean\r
+ * The bean to use as data source.\r
+ */\r
+ public void setItemDataSource(T bean) {\r
+ setItemDataSource(new BeanItem(bean));\r
+ }\r
+\r
@Override\r
public void setItemDataSource(Item item) {\r
if (!(item instanceof BeanItem)) {\r
\r
@Override\r
public void bind(Field field, Object propertyId) {\r
- try {\r
- super.bind(field, propertyId);\r
- } catch (BindException e) {\r
- // System.out.println("Trying to add nested property " +\r
- // propertyId);\r
- if (getItemDataSource() != null\r
- && field.getPropertyDataSource() == null) {\r
- // Workaround for nested properties in BeanItem.\r
-\r
- // FIXME: BeanItem.setAddNestedPropertiesAutomatically would be\r
- // a nice, real fix..\r
- Property p = new NestedMethodProperty(getItemDataSource()\r
- .getBean(), (String) propertyId);\r
- getItemDataSource().addItemProperty(propertyId, p);\r
- super.bind(field, propertyId);\r
+ if (getItemDataSource() != null) {\r
+ // The data source is set so the property must be found in the item.\r
+ // If it is not we try to add it.\r
+ try {\r
+ getItemProperty(propertyId);\r
+ } catch (BindException e) {\r
+ // Not found, try to add a nested property;\r
+ // BeanItem property ids are always strings so this is safe\r
+ getItemDataSource().addNestedProperty((String) propertyId);\r
}\r
}\r
\r
+ super.bind(field, propertyId);\r
}\r
\r
@Override\r