So in the recent Session Planner Quickstart video on the CUBA YouTube, there is some code that uses ScreenBuilders to open a screen in dialog mode instead of the default “full screen” mode, which is precisely what I want in the screen I’m working on.
I have a Patient entity which is being editing - these Patient entities have a 1:1 composition with a PatientAddress entity, which represents their current address (there will also eventually be one each for their former address and alternate address too).
When I auto-generated the screen, the Studio used a pickerField for the current address - which is totally fine. When you invoke it, the editor for PatientAddress uses the default full screen mode, but instead I want it to use dialog mode. So as I said, it seems that code from the video would be perfect.
I subscribed to the open_composition action of the pickerField and used the following adapted code:
@Subscribe("currentAddressField.open_composition")
public void onCurrentAddressFieldOpen_composition(Action.ActionPerformedEvent event) {
Screen screen = screenBuilders.editor(PatientAddress.class, this)
.editEntity(getEditedEntity().getCurrentAddress())
.withLaunchMode(OpenMode.DIALOG).build();
screen.addAfterCloseListener(afterCloseEvent -> {
getScreenData().loadAll();
});
screen.show();
}
It does work (mostly) but there are two problems which I’ve been unable to figure out after poking around in various documentation.
-
When the PatientAddress editor returns back to the Patient editor, the changed address is not displayed; it is still showing the old data. It is correctly persisted in the database, and closing the Patient editor and going back in shows said correct data, but I need it to “refresh” when the popped up editor closes.
-
The PatientAddress editor only works when the Patient already has a current address set. If not, I get an error: “IllegalStateException: Editor of class c.m.m.entity.patient.PatientAddress cannot be open with mode EDIT, entity is not set” So I need it to open with a blank form to enter a new one if it’s not set, or with the existing one pulled up for editing if it does exist. This is exactly how the screen works by default, but popping it up this way in dialog mode doesn’t work.