How to use AfterCommitHandler/refresh when coming from a composite entity create screen

Hey guys,

I hope anyone had come across the same issues as I have. In my example project, I have a Manifest entity, with a composite relationship to a Statusupdate. In the manifest-edit-screen (Which will be a mostly non editable view-screen), I have 5 buttons for giving in a particular statusupdate. Further business logic should force the order of which updates can be given.

When pressing the first button, a statusupdate editor will open, with a pre filled out Statusmessage (shows as non editable, but it will be hidden). After entering the date and committing, a statusupdate entityListener transfers the statusmessage from the statusupdate, to the manifest Batchstatus.

After commiting the statusupdate, want two things to happen, which I cant get to work.

1: I want to refresh the datasource statusupdatesDs when you return back to the manifest edit/view. I’ve came across the statusupdatesD.refresh(), but I cant get that to work ? Maybe because after entering a statusupdate entity, it returns to a parent entity editor/view instead of the statusupdate browser ?

2: After entering a particular statusupdate, when going back to the manifest edit/view, I want the button to be disabled, so the same status cant be inserted twice. Now I have to close the Manifest edit/view, and also the Browser itself, before the page gets reloaded, and the disabled button shows properly. I’ve read about the setAfterCommitHandler, but I can’t get it to work either.

I also came across problem with the 3rd button, which aditionally requires an update to two manifest attributes (The manifest itself is non editable, so this is the only place where you can enter this data). After committing the 3rd statusupdate and attributes, and closing the manifest edit/view, I get the error that the entity was modified in another transaction, which makes sense, since the Manifest got an update by the statusupdate entityListener.

Now I can make an exception in the Listener for this particular status, but since I’m updating datasources and UI elements, perhaps there is also a way to update the manifest entity itself, or even reload the entire open tab ?

Any suggestions would be greatly appreciated! I hope the project makes sense.

example.zip (72.6K)

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 between entities and standalone linked datasource for Statusupdate in the Manifest editor. Just refresh the datasource after closing Statusupdate editors, something like this:

AbstractEditor abstractEditor = openEditor("example$Statusupdate.edit2", log, WindowManager.OpenType.DIALOG);
abstractEditor.addCloseWithCommitListener(() -> statusupdatesDs.refresh());
1 Like

Hey Konstantin,

Thanks for you help. When I started, I wasn’t sure whether to create an association or a composition for this entity. I think I leaned more on the concept of “One can’t exists without the master”, instead of judging if they were entities that should be edited together.

I now used an association, and followed you example, and got it to work.

Thanks again!