Hello everyone, i am having trouble trying to modeling and manipulating the following scenario:
ColetoInventario entity have many ArquivoColeta entities, and one ArquivoColeta have a FileDescriptor association.
On the ColetaInventario edit screen, was add an option to upload multiple files, and then show there on the grid bellow. But, when saving the entity, the following error is displayed:
java.lang.IllegalStateException: An attempt to save an entity with reference to some not persisted entity.
All newly created entities must be saved in the same transaction. Put all these objects to the CommitContext before commit.
The intention is to generate the child entities along with the main record, but I am not getting success in this process.
This is the code of the entity edit screen controller I tried using:
Hi,
I haven’t checked sample project, but from the code you posted it is seen that you don’t put new ArquivoColeta to the data context.
In order for them to be saved on screen commit - they must be in the data context.
To do that, you should:
Inject DataContext to the screen controller
When creating new ArquivoColeta entities, use dataContext.create() instead of metadata.create().
the proposed changes have been made and the routine works.
but we identified a new situation after the routine was released, only the first addition of files is listed in the grid.
after having items in the grid, if the user adds more files, they are not displayed.
but when recording, and accessing the same record, it lists all the files inserted, in both steps.
apparently, it is as if the grid does not update with the data in memory.
something that can be done to list, before it is actually recorded in the database?
As you are saying that these items are displayed in the Grid table, I suppose there is some nested collection container connected to the Grid.
You should inject this container to the screen controller. And then use getMutableItems() to add new items to the collection, like suggested in the manual example: https://doc.cuba-platform.com/manual-7.2/gui_collection_container.html
Hi,
When you are using getMutableItems(), it returns you a “magical” collection which listens for adding / removing items and notifies connected UI components about that.
When you are changing collection directly - UI components are not notified that new items were added.