Hi everyone, I have a detailView of class A with some fields and a datagrid to a class B (o2m relationship) , the B class has a boolean field “principal”. I must assure that there is only one B with principal to true. So i write a method to do that in the “beforeSave” of B detailview, but for some reason the other records remains doesn’t change their principal value. Any ideas why? in the before save code it’s like this
if record.getPrincipal()){ record.getA().getB().stream() .filter(Objects::nonNull) .filter(p -> !record.getCode().equals(p.getCode())) .forEach(p -> p.setPrincipal(false)); }
Thanks
Hi!
Could you please provide a small test project that reproduces the issue?
Best regards,
Dmitriy
Hi!
Thank you for demo project.
Unfortunately, I encountered some difficulties while using it:
- The project lacked build system information, making it impossible to build the project initially. Furthermore, there’s no objective indication of the project’s affiliation with a specific Jamix version. To avoid this, use the framework’s built-in project archiver:
./gradlew zipProject - You used a
postgresdatabase defined on your local machine. My machine doesn’t have apostgresdatabase. Naturally, running the application with this configuration is impossible. To transfer the test project, you need to use a transferable database, such as anH2 File.
On my test project in your case, this problem does not occur:
test-project.zip (122.4 KB)
I hope my test project will help you fix your own.
Best regards,
Dmitriy
Offtop:
I’ll also offer a word of caution. I saw in your code that you use a checkbox component as a renderer. Using a full-fledged component can have a negative impact on performance, because creating a component entails creating both its client-part and server-part. If you have a lot of entities and a lot of checkboxes, this will definitely slow down the app. It’s more optimal to use icons to indicate Boolean values. For example:
@Supply(to = "childDataGrid.principal", subject = "renderer")
private Renderer<B> childDataGridPrincipalRenderer() {
return new ComponentRenderer<>(b -> Boolean.TRUE.equals(b.getPrincipal())
? icons.get(JmixFontIcon.CHECK_SQUARE_O)
: icons.get(JmixFontIcon.THIN_SQUARE));
}