Hi:
I’m going through the Hands-On lab but I only have the free version right now. Instead of display a Pie Chart, I figured I would fill a table with the results of the OrderService.getMechanicOrderStats call. Here is the code I wrote, based on Dynamic Entities - CUBA.Platform link:
public class MechanicBrowse extends AbstractLookup {
@Inject
private OrderService orderService;
@Inject
private Table statsTable;
@Override
public void init(Map<String, Object> params) {
super.init(params);
KeyValueCollectionDatasourceImpl ds = new DsBuilder().buildCollectionDatasource(KeyValueCollectionDatasourceImpl.class);
ds.addProperty("mechanic").addProperty("orders");
Map<Mechanic, Long> stats = orderService.getMechanicOrderStats();
for (Map.Entry<Mechanic, Long> entry: stats.entrySet()) {
KeyValueEntity entity = new KeyValueEntity();
entity.setValue("mechanic", InstanceUtils.getInstanceName(entry.getKey()));
entity.setValue("orders", entry.getValue());
ds.includeItem(entity);
}
statsTable.setDatasource(ds);
statsTable.setVisible(true);
}
}
mechanic-browse.xml contains:
<table id="statsTable"
height="200px"
width="100%">
<columns>
<column id="mechanic"/>
<column id="orders"/>
</columns>
<rows/>
</table>
The code compiles fine, but I get the following error at runtime:
GuiDevelopmentException: Table 'rows' element doesn't have 'datasource' attribute
Frame ID: workshop$Mechanic.browse
XML descriptor: com/company/workshop/gui/mechanic/mechanic-browse.xml
Table ID: statsTable
I’m setting the datasource inside the init function. Why is it not seeing it? What’s the correct way to do this?
Thanks in advance…