3.5.4.7. InputDialogFacet
InputDialogFacet
is a facet that provides an ability to pre-configure an input dialog. Declarative definition of the input dialog replaces existing Dialogs.createInputDialog()
method. InputDialogFacet
is defined in the facets
element of the screen XML descriptor.
Component’s XML-name: inputDialog
.
Usage example:
<facets>
<inputDialog id="inputDialogFacet"
caption="msg://inputDialog"
onAction="dialogAction">
<parameters>
<booleanParameter id="boolParam"
caption="msg://boolParam"
defaultValue="true"
required="true"/>
<intParameter id="intParam"
caption="msg://intParam"
required="true"/>
<entityParameter id="userParam"
caption="msg://userParam"
entityClass="com.haulmont.cuba.security.entity.User"
required="true"/>
</parameters>
</inputDialog>
</facets>
The screen configured with InputDialogFacet
can be shown explicitly using the show()
method:
@Inject
protected InputDialogFacet inputDialog;
@Subscribe("showDialog")
public void onShowDialogClick(Button.ClickEvent event) {
inputDialog.show();
}
Alternatively, the facet can be subscribed to any action (see onAction attribute) or button (see onButton attribute) by id.
In addition to attributes described for the OptionDialogFacet, inputDialog
has the defaultActions
attribute that defines a set of predefined actions to use in a dialog. The standard values are:
-
OK
-
OK_CANCEL
-
YES_NO
-
YES_NO_CANCEL
The default value is OK_CANCEL
.
inputDialog elements:
-
actions
element represents a list of dialog actions.
-
parameters
element may contain the following parameters:-
stringParameter
-
booleanParameter
-
intParameter
-
doubleParameter
-
longParameter
-
bigDecimalParameter
-
dateParameter
-
timeParameter
-
dateTimeParameter
-
entityParameter
-
enumParameter
-
To implement custom logic for a dialog action, you should create an appropriate handler method in the controller.
To handle input dialog results, you can install the corresponding delegate:
@Install(to = "inputDialogFacet", subject = "dialogResultHandler")
public void handleDialogResults(InputDialog.InputDialogResult dialogResult) {
String closeActionType = dialogResult.getCloseActionType().name();
String values = dialogResult.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();
}