Discard changes in a DetailView

Hi,

is there a way to discard changes in edit mode without closing view?

For example to achieve the same result of invoking close(StandardOutcome.DISCARD) but without leave view.

Thanks

Hi,

I guess you may try the following:

  • store an initial state of the edited entity in a separate variable when the screen is opened
  • when the “Reset” button is clicked, copy the state of the initial saved entity into the edited entity
@Route(value = "offices/:id", layout = MainView.class)
@ViewController("Office.detail")
@ViewDescriptor("office-detail-view.xml")
@EditedEntityContainer("officeDc")
public class OfficeDetailView extends StandardDetailView<Office> {

    private Office initialEntity;

    @Autowired
    private MetadataTools metadataTools;

    @Subscribe
    public void onBeforeShow(final BeforeShowEvent event) {
        initialEntity = metadataTools.copy(getEditedEntity());
    }

    @Subscribe("resetBtn")
    public void onResetBtnClick(final ClickEvent<JmixButton> event) {
        metadataTools.copy(initialEntity, getEditedEntity());
    }
}
1 Like

Thanks Maxim, it could be a good solution, but i’m still giving the “You have unsaved changes” dialog after reset