f.zehnder
(F Zehnder)
December 13, 2024, 4:25pm
1
I have adresses with persons as composition ( each adress has several persons who are working at this adress ).
If I add a person in the Detailscreen and Close the screen
<button id="saveAndCloseBtn" action="saveAction"/>
the entity is NOT saved.
Even when I add
public void onBeforeClose(final BeforeCloseEvent event) {
dataContext.save();
}
nothing is saved.
What do I miss ?
Thank you for any help.
Felix
krivopustov
(Konstantin Krivopustov)
December 16, 2024, 7:41am
2
It’s hard to say anything without seeing your code.
Please provide a test project with the entities and views.
Regards,
Konstantin
f.zehnder
(F Zehnder)
December 16, 2024, 1:08pm
3
Hi Konstantin
Attached you find the requested project.
Create an adres
Save this adres with OK
Edit this newly created adres
Create Person, confirm OK
→ After entering the name and pressing the OK Button in the persoDetailView this entity should be stored
Create Contact
→ Because the Person is not stored in the database, it is not possible to store the new contact with this new person ;/
Thank you for trying to understand the “issue”.
Best regards
Felix
SaveEntity.zip (2.3 MB)
krivopustov
(Konstantin Krivopustov)
December 17, 2024, 9:09am
4
Thank you for the explanation and test project.
This is not the case for compositions. The composition items (Perso and Conta) will go to the database only when you save the root entity (Adres). The whole point of compositions is editing aggregates in memory and saving them in a single transaction. See Editing Aggregates .
To get a list of persons in the Conta detail view, pass it from the Adres detail view instead of loading from the database:
Remove loader from persoDC:<collection id="persoDC" class="com.company.saveentity.entity.Perso" />
Add setter to ContaDetailView:public class ContaDetailView extends StandardDetailView<Conta> {
@ViewComponent
private CollectionContainer<Perso> persoDC;
public void setPersons(Collection<Perso> persons) {
persoDC.setItems(persons);
}
}
Invoke it for Conta create and edit actions in AdresDetailView:public class AdresDetailView extends StandardDetailView<Adres> {
@Install(to = "contaDataGrid.create", subject = "viewConfigurer")
private void contaDataGridCreateViewConfigurer(final ContaDetailView contaDetailView) {
contaDetailView.setPersons(getEditedEntity().getPerso());
}
@Install(to = "contaDataGrid.edit", subject = "viewConfigurer")
private void contaDataGridEditViewConfigurer(final ContaDetailView contaDetailView) {
contaDetailView.setPersons(getEditedEntity().getPerso());
}
}
Attached the whole project:
SaveEntity-fixed.zip (2.3 MB)
Regards,
Konstantin
1 Like
f.zehnder
(F Zehnder)
December 17, 2024, 1:20pm
5
Thank you a lot for your explanations and the project.
As I might convert an existing application with a different approach; would it be possible to execute from the perso.onSaveAndCloseButtonClick() the adres.SaveAndCloseButtonClick() ?
Regards
Felix