I’m having an issue auto-populating composition records and getting them to stay on the screen when editing any of them. I’ve created a basic project to show my issues.
These items populate correctly in the composition table on the Order editor when creating a new Order, however, when editing any of these collection entity records and returning to the Order editor, nothing appears in the Milestone collection table. Note, that these entities do save correctly when saving the Order and coming back, but the problem is that they disappear before saving.
I had a very, very similar problem a while back and can’t remember the solution. I’m looking through my post history trying to find it (because I definitely posted about it!) but I can’t find the info yet. O_O
Something to do with having to tell the table that the collection was changed.
Aha - in my case I was creating the new entities into the DataContainer itself via getMutableItems.add(...) - and the programmatically created entities weren’t merged to the DataContext. You’re doing it via creating the entities in the parent entity’s collection, etc - which should be totally valid!
Though you might try the approach of creating them and adding them to the DataContainer and letting it go that way instead. That definitely works.
I really appreciate the help. I wasn’t quite able to get the example working (I suspect because I was calling the methods from onInitEntity() and not everything was set up yet), so I moved my call to the method into onAfterShow() and injected EntityStates (which I’ve never used before).
@Subscribe
public void onAfterShow(AfterShowEvent event) {
if (entityStates.isNew(getEditedEntity)) {
createDefaultMilestones();
}
}
Those steps, along with either of our previous code gets it functioning properly. All is well in the world!!!