Hello,
I have an edit screen with a a Table connected to a collectionDatasource. Y added columns from other table with a ValueCollectionDatasourceImpl using the postInit() according what i found in the forum and it worked. The problem is that the table have a create, edit and remove actions and when i use them the data in the added columns dont refresh.
I tried to use the same aproach used in the postInit() inside the setAfterCommitHandler of the create action of the table but it doesn’t work. how should i do to fix this. Thanks in advance.
@Override
protected void postInit() {
super.postInit();
// This first part works fine;
ValueCollectionDatasourceImpl crds = DsBuilder.create().buildValuesCollectionDatasource();
crds.setQuery(" select distinct p.id, p.nombre from cotpt$ColoresCotizacion e join e.componente p " +
"join e.combo o join o.cotizacionCombo c where c.id = :custom$cotiz" );
List<String> campos = Arrays.asList("id", "nombre");
crds.addProperty(campos.get(0));
crds.addProperty(campos.get(1));
crds.refresh(ParamsMap.of("cotiz", getItem().getId()));
for (KeyValueEntity entity1 : crds.getItems()) {
final String nomColumna = entity1.getValue(campos.get(1));
final UUID idColumna = entity1.getValue(campos.get(0));
comboCotizacionTable.addGeneratedColumn(nomColumna, entity -> {
ValueCollectionDatasourceImpl crds2 = DsBuilder.create().buildValuesCollectionDatasource();
crds2.setQuery(" select l.color from cotpt$ComboCotizacion o join o.coloresCotizacion e join e.componente p join e.color l " +
"join o.cotizacionCombo c where c.id = :custom$cotiz and p.id = :custom$compo and o.nro = :custom$nrocombo " );
List<String> campos2 = Arrays.asList("color");
crds2.addProperty(campos2.get(0));
crds2.refresh(ParamsMap.of("cotiz", getItem().getId(), "compo", idColumna, "nrocombo", entity.getNro() ));
//comboCotizacionTable.getSingleSelected().getNro() getItem().getId()
for (KeyValueEntity entity2 : crds2.getItems()) {
return new Table.PlainTextCell(entity2.getValue(campos2.get(0)));
}
return new Table.PlainTextCell("");
});
}
// This second part was added to update the data adding columns
// if needed after i create new records but doesn't work
comboCotizacionTableCreate.setAfterCommitHandler(entity -> {
ValueCollectionDatasourceImpl crdsa = DsBuilder.create().buildValuesCollectionDatasource();
crdsa.setQuery(" select distinct p.id, p.nombre from cotpt$ColoresCotizacion e join e.componente p " +
"join e.combo o join o.cotizacionCombo c where c.id = :custom$cotiz" );
List<String> camposa = Arrays.asList("id", "nombre");
crdsa.addProperty(camposa.get(0));
crdsa.addProperty(camposa.get(1));
crdsa.refresh(ParamsMap.of("cotiz", getItem().getId()));
for (KeyValueEntity entity1a : crdsa.getItems()) {
final String nomColumna = entity1a.getValue(camposa.get(1));
final UUID idColumna = entity1a.getValue(camposa.get(0));
comboCotizacionTable.addGeneratedColumn(nomColumna, e -> {
ValueCollectionDatasourceImpl crds2a = DsBuilder.create().buildValuesCollectionDatasource();
crds2a.setQuery(" select l.color from cotpt$ComboCotizacion o join o.coloresCotizacion e join e.componente p join e.color l " +
"join o.cotizacionCombo c where c.id = :custom$cotiz and p.id = :custom$compo and o.nro = :custom$nrocombo " );
List<String> campos2a = Arrays.asList("color");
crds2a.addProperty(campos2a.get(0));
crds2a.refresh(ParamsMap.of("cotiz", getItem().getId(), "compo", idColumna, "nrocombo", e.getNro() ));
//comboCotizacionTable.getSingleSelected().getNro() getItem().getId()
for (KeyValueEntity entity2a : crds2a.getItems()) {
return new Table.PlainTextCell(entity2a.getValue(campos2a.get(0)));
}
return new Table.PlainTextCell("");
});
}
});
}