InputDialogFacet

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

Component’s XML-name: inputDialog.

Attributes

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

  • dialogActions - allows you to add the most frequently used actions with the corresponding buttons in the dialog. There are the following possible values:

    • OK_CANCEL - adds the OK and Cancel buttons. The default value.

    • OK - adds the OK button.

    • YES_NO - adds the Yes and No buttons.

    • YES_NO_CANCEL - adds the Yes, No, and Cancel buttons.

  • onAction

  • onButton

Actions

See actions.

Parameters

To add input fields in the dialog, use the parameters element of the screen XML descriptor to put the following subelements. For each parameter, a corresponding visual component will be created for entering the value.

Parameter Visual Component

bigDecimalParameter

TextField with the decimal data type

dateParameter

DateField with the DAY resolution

dateTimeParameter

DateField with the MIN resolution

doubleParameter

TextField with the double data type

intParameter

TextField with the int data type

longParameter

TextField with the long data type

stringParameter

TextField

timeParameter

TimeField

All the parameters described above have the defaultValue attribute for setting the default value for the corresponding field.

<parameters>
    <bigDecimalParameter id="bigDecimalParameter"
                         caption="Big Decimal Parameter"
                         defaultValue="55.753"
                         required="false"/>
</parameters>
  • entityParameter - will be displayed EntityPicker. To define the entity class for the corresponding field, use the entityClass attribute.

    <parameters>
        <entityParameter caption="Entity Parameter"
                         entityClass="ui.ex1.entity.City"
                         id="entityParameter"
                         required="true"/>
    </parameters>
  • enumParameter - will be displayed ComboBox. To define the enum class for the corresponding field, use the enumClass attribute.

    <parameters>
        <enumParameter caption="Enum Parameter"
                       enumClass="ui.ex1.entity.Hobby"
                       id="enumParameter"/>
    </parameters>

Events and Handlers

To generate a handler stub in Jmix Studio, select the facet in the screen descriptor XML or in the Component Hierarchy panel and use the Handlers tab of the Component Inspector panel.

Alternatively, you can use the Generate Handler button in the top panel of the screen controller.

InputDialogCloseEvent

To handle dialog closing use InputDialogCloseEvent. With the help of the InputDialogCloseEvent.closedWith() method, you can track how the dialog was closed.

@Autowired
private Notifications notifications;

@Subscribe("inputDialog")
public void onInputDialogInputDialogClose(InputDialog.InputDialogCloseEvent event) {
    if (event.closedWith(DialogOutcome.OK)) {
        notifications.create()
                .withCaption("The order will display in your profile within 5 minutes")
                .show();
    }
}

Programmatic registration of the event handler: use the addCloseListener() component method.

DialogResultHandler

To handle input dialog results, you can use DialogResultHandler:

@Autowired
private Notifications notifications;

@Install(to = "inputDialog", subject = "dialogResultHandler")
private void inputDialogDialogResultHandler(InputDialog.InputDialogResult inputDialogResult) {
    String closeActionType = inputDialogResult.getCloseActionType().name();

    String values = inputDialogResult.getValues().entrySet()
            .stream()
            .map(entry -> String.format("%s = %s", entry.getKey(), entry.getValue()))
            .collect(Collectors.joining(", "));

    notifications.create(Notifications.NotificationType.HUMANIZED)
            .withCaption("InputDialog Result Handler")
            .withDescription("Close Action: " + closeActionType +
                    ". Values: " + values)
            .show();
}

Programmatic usage: call the setDialogResultHandler() component method.

Validator

To validate input values, InputDialogFacet has Validator. It receives specific InputDialog.ValidationContext, which contains values and input dialog. The Validator must return the ValidationErrors instance, which includes descriptions for errors. These errors will be shown in a notification with other validation exceptions.

@Install(to = "inputDialog", subject = "validator")
private ValidationErrors inputDialogValidator(InputDialog.ValidationContext validationContext) {
    String phone = validationContext.getValue("phoneField");
    String address = validationContext.getValue("addressField");
    if (Strings.isNullOrEmpty(phone) && Strings.isNullOrEmpty(address)) {
        return ValidationErrors.of("Phone or Address must be filled");
    }
    return ValidationErrors.none();
}

Programmatic usage: call the setValidator() component method.

All XML Attributes

You can view and edit attributes applicable to the facet using the Component Inspector panel of the Studio’s Screen Designer.