Hi
I need refresh browse include edit window. I modify datasource in postCommit method
protected boolean postCommit(boolean committed, boolean close) {
boolean result = super.postCommit(committed, close);
if ((committed) && (result)) {
LoadContext<DocTypesToLedger> lc = new LoadContext<>(DocTypesToLedger.class);
DocTypesToLedger curritem = (DocTypesToLedger) getContext().getParams().get("ITEM");
if (def.getValue()) {
Integer ledgerId = curritem.getLedger().getId();
lc.setQueryString("select r from publisher$DocTypesToLedger r where r.ledger.id = :ledger")
.setParameter("ledger", ledgerId);
lc.setView(View.BASE);
List<DocTypesToLedger> list = docTypesToLedgerDs.getDataSupplier().loadList(lc);
for (DocTypesToLedger item : list) {
if (!(item.getId().equals(curritem.getId()))) {
item.setIsdefault(false);
docTypesToLedgerDs.getDataSupplier().commit(item);
}
}
}
}
return result;
}
I find topic abou it and I add in browse in init method refresh – > setAfterCommitHandler(entity -> docTypesToLedgersDs.refresh())
but browse doesn’t refresh.
shiryaeva
(Olga Shiryaeva)
May 21, 2018, 8:27am
#3
Hi,
I’ve tried to implement your idea in the CUBA Quick Start sample application, and it works:
OrderBrowse.java :
public class OrderBrowse extends AbstractLookup {
@Named("ordersTable.create")
private CreateAction ordersTableCreate;
@Inject
private GroupDatasource<Order, UUID> ordersDs;
@Override
public void init(Map<String, Object> params) {
ordersTableCreate.setAfterCommitHandler(entity -> {
showNotification("Committed in editor", NotificationType.HUMANIZED);
ordersDs.refresh();
});
}
}
OrderEdit.java :
public class OrderEdit extends AbstractEditor<Order> {
@Inject
private Datasource<Order> orderDs;
@Override
protected boolean postCommit(boolean committed, boolean close) {
boolean result = super.postCommit(committed, close);
if (committed && result) {
LoadContext<Order> loadContext = new LoadContext<>(Order.class);
UUID orderId = getItem().getId();
loadContext.setQueryString("select e from sales$Order e where e.id = :orderId")
.setParameter("orderId", orderId);
loadContext.setView("order-with-customer");
Order order = orderDs.getDataSupplier().load(loadContext);
if (order != null) {
order.setAmount(order.getAmount().multiply(new BigDecimal(100000)));
orderDs.getDataSupplier().commit(order);
}
}
return result;
}
}
Here it is: sales.zip (85.8 KB)
It would be helpful if you could attach a sample of your project.
I explain my problem precisely. I have edit window like this
I would like refresh documentList browse. When I create setAfterCommitHandler in this browse controler I have no effect because this code is never running, but I may create setAfterCommitHandler in Ledger editor. When I accept documentList edit window I give message committed in editor and bowser no refresh.
shiryaeva
(Olga Shiryaeva)
May 22, 2018, 9:08am
#5
I see. You can use the Events mechanism .
See also:
Hi Jeroen, Why do you use composition here? Composition simplifies joint editing of entities, but what you are doing doesn’t look like editing, it’s the whole business process. I think both problems could be easily solved if you use association...
Hi Olga.
Might I send my project to us ? I try all possibilities. I use refresh browse in other function and it’s woking ok.
I thing, It’s specific issue because browse is inner edit window.
shiryaeva
(Olga Shiryaeva)
May 22, 2018, 2:27pm
#7
Yes, a small sample project would be really helpful, or at least the clear explanation of your data model and the code of screen descriptors and controllers.
Hi
I attach my project. I update data in class DocTypesToLedgerEdit method postCommit and I try refresh browse in addCloseWithCommitListener in this same class. Publisher.zip (1.1 MB)