TemplateRenderer.withProperty overwrites previous property definition
See original GitHub issueI have a grid with several columns, each column is generated by a TemplateRenderer
. The grid instance itself is initialized from a polymer template.
Two of these columns are referring to properties of the same type (Person
). To keep the details (like the person’s role) out of the template, the properties are both put with the name person
into the template. The result of this is, that the second declaration overwrites the first one.
For me this behavior is intransparent, since I define the property at the renderer instance and not the grid and would therefore expect some local scope.
So request is, that properties defined for a TemplateRenderer
should be available only in this instance and do not overwrite other renderer instances.
If this is not possible due to technical reasons, then the property definition should be moved away from the TemplateRenderer
to the Grid
(or some other instance within the grid wide scope).
Grid column definition
@Id("grid")
private Grid<Project> projectGrid;
@PostConstrcut
private void init() {
// ...
projectGrid.addColumn(TemplateRenderer.<Project>of("<div>[[item.person.name]]</div>").withProperty("person", Project::getDeliveryLead));
projectGrid.addColumn(TemplateRenderer.<Project>of("<div>[[item.person.name]]</div>").withProperty("person", Project::getAccountManager)); // this overrides the previous set "deliveryLead"
// ...
}
Beans
public class Project {
private Person deliveryLead;
private Person accountManager;
// ...
}
public class Person {
private String name;
// ...
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:14 (12 by maintainers)
Top GitHub Comments
Got the same problem. If you have 2 TemplateRenderer with the same property (like value), sometimes it will show the first one, sometimes the second one.
It’s pretty hard to debug it in a project. (especially in Java it fetches the correct values)
To avoid this, I used a uuid string, so my property is unique.
Should this be documented somewhere?
@pleku I understand that “in the future the
TemplateRenderer
is going to be replaced” but I hope this future is very close since AFAIKTemplateRenderer
is the only alternative toComponentRenderer
which does not slow down the grid (see https://vaadin.com/blog/using-the-right-r).