3.5.4.6. OptionDialogFacet

OptionDialogFacet is a facet that provides an ability to pre-configure an option dialog. Declarative definition of the option dialog replaces existing Dialogs.createOptionDialog() method. OptionDialogFacet is defined in the facets element of the screen XML descriptor.

Component’s XML-name: optionDialog.

Usage example:

<facets>
    <optionDialog id="optionDialog"
                  caption="msg://optionDialogCaption"
                  message="msg://optionDialogMsg"
                  onAction="dialogAction">
        <actions>
            <action id="ok"
                    caption="msg://optDialogOk"
                    icon="CHECK"
                    primary="true"/>
            <action id="cancel"
                    caption="msg://optDialogCancel"
                    icon="BAN"/>
        </actions>
    </optionDialog>
</facets>

The screen configured with OptionDialogFacet can be shown explicitly using the show():

@Inject
protected OptionDialogFacet optionDialog;

@Subscribe("showDialog")
public void onShowDialogClick(Button.ClickEvent event) {
    optionDialog.show();
}

Alternatively, the facet can be subscribed to any action (see onAction attribute) or button (see onButton attribute) by id.

optionDialog has the actions element, which represents a list of dialog actions.

To implement custom logic for a dialog action, you should create an appropriate handler method in the controller:

@Inject
protected OptionDialogFacet optionDialog;
@Inject
protected Notifications notifications;

@Install(to = "optionDialog.ok", subject = "actionHandler") (1)
protected void onDialogOkAction(DialogActionPerformedEvent<OptionDialogFacet> event) {
    String actionId = event.getDialogAction().getId();

    notifications.create(Notifications.NotificationType.TRAY)
            .withCaption("Dialog action performed: " + actionId)
            .show();
}

@Install(to = "optionDialog.cancel", subject = "actionHandler") (2)
protected void onDialogCancelAction(DialogActionPerformedEvent<OptionDialogFacet> event) {
    String actionId = event.getDialogAction().getId();

    notifications.create(Notifications.NotificationType.TRAY)
            .withCaption("Dialog action performed: " + actionId)
            .show();
}
1 - a handler that is invoked when the user clicks the OK button in the option dialog.
2 - a handler that is invoked when the user clicks the Cancel button in the option dialog.

Attributes of optionDialog

caption - contentMode - height - htmlSanitizerEnabled - id - maximized - message - onAction - onButton - stylename - width

Element of optionDialog

actions