Skip to content

Latest commit

 

History

History
81 lines (70 loc) · 4.82 KB

File metadata and controls

81 lines (70 loc) · 4.82 KB
Screen Events

This section describes the screen lifecycle events that can be handled in controllers.

  • InitEvent is sent when the screen controller and all its declaratively defined components are created, and dependency injection is completed. Nested fragments are not initialized yet. Some visual components are not fully initialized, for example buttons are not linked with actions.

    link:../../../../../../source/gui/screens/screen_InitEvent.java[role=include]
  • AfterInitEvent is sent when the screen controller and all its declaratively defined components are created, dependency injection is completed, and all components have completed their internal initialization procedures. Nested screen fragments (if any) have sent their InitEvent and AfterInitEvent. In this event listener, you can create visual and data components and perform additional initialization if it depends on initialized nested fragments.

  • InitEntityEvent is sent in screens inherited from StandardEditor and MasterDetailScreen before the new entity instance is set to edited entity container. Use this event listener to initialize default values in the new entity instance, for example:

    link:../../../../../../source/gui/screens/screen_InitEntityEvent.java[role=include]
  • BeforeShowEvent is sent right before the screen is shown, i.e. it is not added to the application UI yet. Security restrictions are applied to UI components. Saved component settings are not yet applied to UI components. Data is not loaded yet for screens annotated with @LoadDataBeforeShow. In this event listener, you can load data, check permissions and modify UI components. For example:

    link:../../../../../../source/gui/screens/screen_BeforeShowEvent.java[role=include]
  • AfterShowEvent is sent right after the screen is shown, i.e. when it is added to the application UI. Saved component settings are applied to UI components. In this event listener, you can show notifications, dialogs or other screens. For example:

    link:../../../../../../source/gui/screens/screen_AfterShowEvent.java[role=include]
  • BeforeCloseEvent is sent right before the screen is closed by its close(CloseAction) method. The screen is still displayed and fully functional. Component settings are not saved yet. In this event listener, you can check any conditions and prevent screen closing using the preventWindowClose() method of the event, for example:

    link:../../../../../../source/gui/screens/screen_BeforeCloseEvent.java[role=include]

    There is also an event with the same name but defined in the Window interface. It is sent before the screen is closed by an external (relative to the controller) action, like clicking on the button in the window tab or by pressing the Esc key. The way the window is closed can be obtained using the getCloseOrigin() method which returns a value implementing the CloseOrigin interface. Its default implementation CloseOriginType has three values:

    • BREADCRUMBS - the screen is closed by clicking on the breadcrumbs link.

    • CLOSE_BUTTON - the screen is closed by the close button in the window header or by the window tab close button or context menu actions: Close, Close All, Close Others.

    • SHORTCUT - the screen is closed by the keyboard shortcut defined in the cuba.gui.closeShortcut application property.

      You can subscribe to Window.BeforeCloseEvent by specifying Target.FRAME in the @Subscribe annotation:

      link:../../../../../../source/gui/screens/window_BeforeCloseEvent.java[role=include]
  • AfterCloseEvent is sent after the screen is closed by its close(CloseAction) method and after Screen.AfterDetachEvent. Component settings are saved. In this event listener, you can show notifications or dialogs after closing the screen, for example:

    link:../../../../../../source/gui/screens/screen_AfterCloseEvent.java[role=include]
  • AfterDetachEvent is sent after the screen is removed from the application UI when it is closed by the user or when the user logs out. This event listener can be used for releasing resources acquired by the screen. Note that this event is not sent on HTTP session expiration.

  • UrlParamsChangedEvent is sent when browser URL parameters corresponding to opened screen are changed. It is fired before the screen is shown, which enables to do some preparatory work. In this event listener, you can load some data or change screen controls state depending on new parameters:

    link:../../../../../../source/gui/screens/screen_UrlParamsChangedEvent.java[role=include]