InputDialogFacet

InputDialogFacet gives you an alternative way to configure and open an input dialog. Instead of using the Dialogs.createInputDialog() method in the screen controller, you can configure InputDialogFacet in the XML descriptor with the help of Studio visual designer.

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 to 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 - defines id of an action which should trigger the dialog opening.

  • onButton - defines id of a button which should trigger the dialog opening.

Actions

See actions.

Parameters

To add input fields to the dialog, create the nested elements listed below inside the parameters element. 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>
  • Use entityParameter to display 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>
  • Use enumParameter to display 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

The InputDialogCloseEvent is sent when the dialog is closed. 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 be displayed in your profile within 5 minutes")
                .show();
    }
}

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

DialogResultHandler

The DialogResultHandler delegate method allows you to handle input dialog results:

@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() method.

Validator

The Validator delegate method allows you to validate input values. It receives specific InputDialog.ValidationContext, which contains entered values. The method 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() 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.