private final PropertyDefinition<T, ?> parent;
- private boolean useLongFormName = false;
-
public NestedBeanPropertyDefinition(BeanPropertySet<T> propertySet,
PropertyDefinition<T, ?> parent,
PropertyDescriptor descriptor) {
super(propertySet, parent.getType(), descriptor);
this.parent = parent;
}
-
- /**
- * Create nested property definition. Allows use of a long form name.
- *
- * @param propertySet
- * property set this property belongs to
- * @param parent
- * parent property for this nested property
- * @param descriptor
- * property descriptor
- * @param useLongFormName
- * use format grandparent.parent.property for name if
- * {@code true}, needed when creating nested definitions
- * recursively like in findNestedDefinitions
- * @since 8.2
- */
- public NestedBeanPropertyDefinition(BeanPropertySet<T> propertySet,
- PropertyDefinition<T, ?> parent, PropertyDescriptor descriptor,
- boolean useLongFormName) {
- this(propertySet, parent, descriptor);
- this.useLongFormName = useLongFormName;
- }
-
+
@Override
public ValueProvider<T, V> getGetter() {
return bean -> {
return Optional.of(setter);
}
+ @Override
+ public String getName() {
+ return parent.getName() + "." + super.getName();
+ }
+
+ @Override
+ public String getTopLevelName() {
+ return super.getName();
+ }
+
private Object writeReplace() {
/*
* Instead of serializing this actual property definition, only
* property definition from the cache.
*/
return new SerializedPropertyDefinition(getPropertySet().beanType,
- parent.getName() + "." + super.getName());
+ getName());
}
+
/**
* Gets the parent property definition.
public PropertyDefinition<T, ?> getParent() {
return parent;
}
-
- @Override
- public String getName() {
- if (useLongFormName) {
- return parent.getName() + "." + super.getName();
- }
- return super.getName();
- }
-
}
/**
PropertyDescriptor subDescriptor = BeanUtil
.getPropertyDescriptor(beanType, name);
moreProps.put(name, new NestedBeanPropertyDefinition<>(this,
- parentProperty, subDescriptor, true));
+ parentProperty, subDescriptor));
}
} catch (IntrospectionException e) {
PropertyDefinition<BEAN, ?> definition) {
Class<?> actualBeanType = findBeanType(beanType, definition);
BeanValidator validator = new BeanValidator(actualBeanType,
- definition.getName());
+ definition.getTopLevelName());
if (requiredConfigurator != null) {
configureRequired(binding, definition, validator);
}
BeanDescriptor descriptor = validator.getJavaxBeanValidator()
.getConstraintsForClass(propertyHolderType);
PropertyDescriptor propertyDescriptor = descriptor
- .getConstraintsForProperty(definition.getName());
+ .getConstraintsForProperty(definition.getTopLevelName());
if (propertyDescriptor == null) {
return;
}
--- /dev/null
+package com.vaadin.data;
+
+import org.junit.Test;
+
+import com.vaadin.ui.Grid;
+
+public class NestedPropertyNameTest {
+
+ @Test
+ public void nestedProperty_sameNameCanBeAdded() {
+ Grid<Person> grid = new Grid<>(Person.class);
+ grid.addColumn("street.name");
+ }
+
+ private class Person{
+ String name;
+ Street street;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Street getStreet() {
+ return street;
+ }
+
+ public void setStreet(Street street) {
+ this.street = street;
+ }
+
+ }
+
+ private class Street{
+ String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+ }
+}