OptionDialogFacet

OptionDialogFacet is a facet that allows you to pre-configure an option dialog. Declarative definition of the message dialog replaces existing Dialogs.createOptionDialog() method.

Component’s XML-name: optionDialog.

Attributes

OptionDialogFacet is defined in the facets element of the screen XML descriptor and has the following attributes:

Actions

To add buttons for user reaction, use the actions element of the screen XML descriptor. The action elements should be placed inside this element. For example:

<optionDialog id="optionDialog">
    <actions>
        <action id="ok"
                caption="OK"
                icon="CHECK"
                primary="true"/>
        <action id="cancel"
                caption="Cancel"
                icon="BAN"
                description="The changes will not be saved"/>
    </actions>
</optionDialog>

To configure action, there are the following attributes:

  • description - defines the text that will be displayed when the cursor hovers over the corresponding button.

  • icon - defines the icon for the corresponding button.

  • primary - defines whether the corresponding button is highlighted and selected. The default value is false.

To implement custom logic for action, use the DialogActionPerformedEvent listener:

@Autowired
protected Notifications notifications;

@Install(to = "optionDialog.ok", subject = "actionHandler")
protected void onDialogOkAction(ActionsAwareDialogFacet.DialogActionPerformedEvent<OptionDialogFacet> event) {
    String actionId = event.getDialogAction().getId();
    notifications.create(Notifications.NotificationType.TRAY)
            .withCaption("Dialog action performed: " + actionId)
            .show();
}

The code inside this listener will be executed when the user clicks the button with id="ok" in the option dialog.

Usage Example

<window xmlns="http://jmix.io/schema/ui/window"
        caption="msg://optionDialogFacetScreen.caption">
    <facets>
        <optionDialog id="optionDialog"
                      caption="Option Dialog"
                      message="Message"
                      onButton="optionDialogBtn"> (1)
            <actions>
                <action id="ok"
                        caption="OK"
                        icon="CHECK"
                        primary="true"/> (2)
                <action id="cancel"
                        caption="Cancel"
                        icon="BAN"
                        description="The changes will not be saved"/> (3)
            </actions>
        </optionDialog>
    </facets>
    <layout>
        <button id="optionDialogBtn"
                caption="Show OptionDialog"/> (4)
    </layout>
</window>
1 Define OptionDialogFacet inside the facets element.
2 Add the first action and set the primary attribute to true.
3 Add the second action and define the description attribute for it.
4 Define button that will open the option dialog.

All XML Attributes

You can view and edit attributes applicable to the facet using the Jmix UI inspector panel of the Studio’s Screen Designer.