Jmix version: 1.5.1
Jmix Studio plugin version: 1.5.2-231
IntelliJ IDEA 2023.1 (Community Edition)
Build #IC-231.8109.175, built on March 28, 2023
Runtime version: 17.0.6+10-b829.5 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
GC: G1 Young Generation, G1 Old Generation
Kotlin: 231-1.8.20-IJ8109.175
Java 17.0.4 2022-07-19 LTS
Java™ SE Runtime Environment (build 17.0.4+11-LTS-179)
Java HotSpot™ 64-Bit Server VM (build 17.0.4+11-LTS-179, mixed mode, sharing)
Operating System: macOS 13.2.1 (22D68)
File System: Case-Sensitive Journaled HFS+ (APFS)
Datebase: PostgreSQL 13
Hello Everyone
For your information, I have a problem with a transient Boolean attribute. My code was working in CUBA and for several versions of Jmix after my migration; I found the problem last week before upgrading to version 1.5.1.
The idea is:
- Entity A contains two many-to-many relationships, one to instances of Entity B and one to Entity C.
- In my Entity A edit screen I have a separate table for each of the Entity B and Entity C instances.
- When the user creates a new Entity B instance, he has the option in the Entity B edit screen to automatically create a new corresponding Entity C instance.
- This option is represented by a transient Boolean attribute in Entity B, e.g. createEntityCInstance.
The process is:
- In my Entity A edit screen the user chooses “Add” from the Entity B table.
@Subscribe("entityBTable.add")
public void onEntityBTableAdd(Action.ActionPerformedEvent event) {
screenBuilders.lookup(entityB.class, this)
.withOpenMode(OpenMode.DIALOG)
.withSelectHandler(entityB ->
entityB.stream()
.map(this::createEntityB)
.forEach(this::addEntityB)
)
.build()
.show();
}
- An Entity B browser screen is presented to the user as a dialog.
- If the user does not find the Entity B instance that they want in the browser list, then they can choose “Create” in the Entity B browser screen.
- The newly created Entity B instance, with the transient “createEntityCInstance” attribute set to “false”, …
@JmixProperty
@Transient
protected Boolean createEntityCInstance = false;
is passed on to the Entity B edit screen …
@Subscribe("entityBsable.create")
public void onEntityBTableCreate(Action.ActionPerformedEvent event) {
entityB entityB = dataContext.create(entityB.class);
screenBuilders.editor(entityBsTable)
.newEntity(entityB)
.withOpenMode(OpenMode.DIALOG)
.withScreenClass(entityBEdit.class)
.withAfterCloseListener(afterScreenCloseEvent -> {
if (afterScreenCloseEvent.closedWith(StandardOutcome.COMMIT)) {
OK here -> entityB newEntityB = afterScreenCloseEvent.getSource().getEditedEntity();
after Close entityBTable.setSelected(newEntityB);
}
})
.build()
.show();
}
- The user must choose some other Entity B instance attributes and they can select a checkbox to set the transient “createEntityCInstance” attribute to “true” to optionally create a new corresponding Entity C instance.
- When the user presses OK in the Entity B edit screen, the new Entity B is saved (commit) and the user is returned to the Entity B browser screen and the new Entity B instance is automatically selected; see the withAfterCloseListener() code above.
- At this point in time everything is correct; I can see in the debugger that my new Entity B transient “createEntityCInstance” attribute is still set to “true” in the Entity B browser screen; see “OK here → after Close” above.
- When I press “Select”, which closes my Entity B browser screen and returns the user to the Entity A edit screen, I return the new Entity B instance in the withSelectHandler() code but at this point the transient “createEntityCInstance” attribute is not “true” anymore; therefore, a new Entity C instance is not created as was requested; see “NOK here → after Select” below.
This is the same code as listed above in the first section …
@Subscribe("entityBsTable.add")
public void onentityBsTableAdd(Action.ActionPerformedEvent event) {
screenBuilders.lookup(entityB.class, this)
.withOpenMode(OpenMode.DIALOG)
.withSelectHandler(entityB ->
NOK here -> entityB.stream()
after Select .map(this::createEntityB)
.forEach(this::addEntityB)
)
.build()
.show();
}
Originally, the transient “createEntityCInstance” attribute was not selected in my fetchPlans.xml, so I added it everywhere yesterday but the result is the same.
Can you please help me resolve this problem.
Thanks in advance.
Best regards
Chris