jmix-framework / jmix

Jmix framework
https://www.jmix.io
Apache License 2.0
695 stars 125 forks source link

ViewConfigurer is fired after entity is set to container #3724

Closed glebfox closed 1 month ago

glebfox commented 2 months ago

Environment

Jmix version: 2.3

Bug Description

ViewConfigurer is fired after entity is set to container, i.e. after InitEntityEvent is fired.

Steps To Reproduce

Assume that InitEntityEvent handles custom parameter, e.g.:

@Subscribe
public void onInitEntity(final InitEntityEvent<TimeEntry> event) {
    TimeEntry timeEntry = event.getEntity();

    if (ownTimeEntry) {
         ...
    }
     ...
}

Using the following code to initialize ownTimeEntry, i.e. ViewConfigurer, we won't get passes value, because ViewConfigurer is fired after InitEntityEvent is fired.

@Subscribe("calendar")
public void onCalendarDayNavigationLinkClick(final DayNavigationLinkClickEvent event) {
    dialogWindows.detail(this, TimeEntry.class)
            .withViewClass(TimeEntryDetailView.class)
            .newEntity()
            .withInitializer(timeEntry ->
                    timeEntry.setDate(event.getDate()))
            .withViewConfigurer(view ->
                    view.setOwnTimeEntry(true))
            .withAfterCloseListener(closeEvent -> {
                if (closeEvent.closedWith(StandardOutcome.SAVE)) {
                    TimeEntry timeEntry = closeEvent.getView().getEditedEntity();
                    timeEntriesDc.getMutableItems().add(timeEntry);
                }
            })
            .open();
}

Current Behavior

ViewConfigurer is fired after InitEntityEvent is fired.

Expected Behavior

ViewConfigurer is fired before InitEntityEvent is fired.

SergeiAksenov2 commented 1 month ago

Tested on: Jmix version: 2.4.999-SNAPSHOT Jmix Studio plugin version: 2.4.SNAPSHOT6867-241 IntelliJ version: IntelliJ IDEA 2024.1.6 (Community Edition)