I have a browse-edit combined screen that extends AbstractLookup class.
At some point I modify an item so my entitysDs datasource becomes modified. I don’t do any commits and later on I refresh that datasource and it becomes unmodified and with the same initial entities. I have to mention that entityDs is also unmodified with item=null.
When pressing on the x button of the window or when pressing ESC key the window shows me a notification that I have some unsaved data.
Why does the window thinks that I have unsaved data while the two datasources are unmodified? Is there a property that belongs to the window that needs to be refreshed as well?
Which window methods are called when pressing ESC key and x button? I may need to override them at some point.
Let’s say I managed to force the closing operation for x button like this: this.addBeforeCloseWithCloseButtonListener(l-> close(CLOSE_ACTION_ID, true));
When trying to do the same for ESC key it generates NULL pointer exception so it’s not a good solution. this.addBeforeCloseWithShortcutListener(l-> close(CLOSE_ACTION_ID, true));
It’s hard to guess what changes makes your data source modified without a sample project. Nevertheless, you can try to debug the com.haulmont.cuba.web.gui.WebWindow#close(java.lang.String) method and find out the reason why the notification appears.
Unfortunately, I can’t reproduce the NPE. Perhaps it’s related to your screen code. But again, it’s hard to guess without a sample project or, at least, exception stack trace.
I’ve debugged the WebWindow#close(java.lang.String) method and I’ve learned that one of my nested datasources is modified. I’ve tried to clear it up with .clear() , .refresh() , .invalidate() calls with no result.
I’ve just created a sample project, please find it attached.
Could you please help me to reset that nested datasource (contactDetailListDs)?
In the meantime I’ve managed to remove the hanged item from itemsToCreate list contained in the contactDetailListDs with the following code so this issued is solved: for(UUID id : contactDetailListDs.getItemIds()) contactDetailListDs.removeItem(contactDetailListDs.getItem(id));
I’ve also managed to set the modified attribute to false using the following code: ((CollectionPropertyDatasourceImpl<ContactDetail, UUID>)contactDetailListDs).committed(new HashSet<>());
Nonetheless I feel this is an unorthodox approach to reset the modified parameter. Is it there a better one?
I investigated your project. You tried to create a master-detail screen from a scratch and in your realization, the detailed view doesn’t become read-only after entity edited. As a result, an entity can be edited and there is no option to save changes.
I would suggest creating this screen using predefined master-detail template in CUBA Studio, at least as a starter point.