Package io.jmix.ui
Interface Dialogs.InputDialogBuilder
- All Superinterfaces:
Dialogs.DialogBuilder<Dialogs.InputDialogBuilder>
,Dialogs.HasCaption<Dialogs.InputDialogBuilder>
,Dialogs.HasSize<Dialogs.InputDialogBuilder>
- All Known Implementing Classes:
DialogsImpl.InputDialogBuilderImpl
- Enclosing interface:
- Dialogs
public static interface Dialogs.InputDialogBuilder
extends Dialogs.DialogBuilder<Dialogs.InputDialogBuilder>
Builder for dialogs with inputs.
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds the input dialog.show()
Shows the dialog.withActions
(DialogActions actions) Sets predefined dialog actions.withActions
(DialogActions actions, Consumer<InputDialog.InputDialogResult> resultHandler) Sets dialog actions and result handler.withActions
(InputDialogAction... actions) Sets dialog actions.Add close listener to the dialog.withParameter
(InputParameter parameter) Adds input parameter to the dialog.withParameters
(InputParameter... parameters) Sets input parameters.Sets additional handler for field validation.Methods inherited from interface io.jmix.ui.Dialogs.HasCaption
getCaption, withCaption
Methods inherited from interface io.jmix.ui.Dialogs.HasSize
getHeight, getHeightSizeUnit, getWidth, getWidthSizeUnit, withHeight, withWidth
-
Method Details
-
withParameter
Adds input parameter to the dialog. InputParameter describes field which will be used in the input dialog.Example:
dialogs.createInputDialog(this) .withParameter( entityParameter("userField", User.class) .withCaption("User field") .withRequired(true) ) .show();
- Parameters:
parameter
- input parameter that will be added to the dialog- Returns:
- builder
- See Also:
-
withParameters
Sets input parameters. InputParameter describes field which will be used in the input dialog.Example:
dialogs.createInputDialog(this) .withParameters( stringParameter("nameField") .withCaption("Name field caption") .withDefaultValue("default value"), intParameter("countField") .withCaption("Count field caption") .withRequired(true)) .show();
- Parameters:
parameters
- input parameters- Returns:
- builder
- See Also:
-
withCloseListener
Add close listener to the dialog. See close actions forDialogActions
inInputDialog
.- Parameters:
listener
- close listener to add- Returns:
- builder
-
withActions
Sets dialog actions.InputDialogAction
provides access to input dialog inInputDialogAction.InputDialogActionPerformed
where it is possible to get values form the fields and implement logic to close dialog.Note, if there is no actions are set input dialog will use
Example:DialogActions.OK_CANCEL
by default.dialogs.createInputDialog(this) .withCaption("Dialog caption") .withParameter(parameter("nameField").withCaption("Name")) .withActions( action("okAction") .withCaption("OK") .withIcon(JmixIcon.DIALOG_OK) .withHandler(event -> { InputDialog inputDialog = event.getInputDialog(); String name = inputDialog.getValue("nameField"); // do logic inputDialog.close(InputDialog.INPUT_DIALOG_OK_ACTION); }), action("cancelAction") .withCaption("Cancel") .withIcon(JmixIcon.DIALOG_CANCEL) .withValidationRequired(false) .withHandler(event -> { InputDialog inputDialog = event.getInputDialog(); inputDialog.close(InputDialog.INPUT_DIALOG_CANCEL_ACTION); })) .show();
- Parameters:
actions
- actions- Returns:
- builder
- See Also:
-
withActions
Sets predefined dialog actions. "OK" and "YES" actions always check fields validation before close the dialog. By default if there is no actions are set input dialog will useDialogActions.OK_CANCEL
.- Parameters:
actions
- actions- Returns:
- builder
-
withActions
Dialogs.InputDialogBuilder withActions(DialogActions actions, Consumer<InputDialog.InputDialogResult> resultHandler) Sets dialog actions and result handler. "OK" and "YES" actions always check fields validation before close the dialog. Handler is invoked after close event and can be used instead ofwithCloseListener(Consumer)
. Exampledialogs.createInputDialog(this) .withCaption("Dialog caption") .withParameter(parameter("nameField").withCaption("Name")) .withActions(DialogActions.OK_CANCEL, result -> { switch (result.getCloseActionType()) { case OK: String name = result.getValue("nameField"); // do logic break; case CANCEL: // do logic break; } }) .show();
- Parameters:
actions
- dialog actionsresultHandler
- result handler- Returns:
- builder
-
withValidator
Dialogs.InputDialogBuilder withValidator(Function<InputDialog.ValidationContext, ValidationErrors> validator) Sets additional handler for field validation. It receives input dialog context and must returnValidationErrors
instance. Returned validation errors will be shown with another errors from fields. Exampledialogs.createInputDialog(this) .withParameters( stringParameter("phoneField").withCaption("Phone"), stringParameter("addressField").withCaption("Address")) .withValidator(context -> { String phone = context.getValue("phoneField"); String address = context.getValue("addressField"); if (Strings.isNullOrEmpty(phone) && Strings.isNullOrEmpty(address)) { return ValidationErrors.of("Phone or Address should be filled"); } return ValidationErrors.none(); }) .show();
- Parameters:
validator
- validator- Returns:
- builder
-
show
InputDialog show()Shows the dialog.- Returns:
- opened input dialog
-
build
InputDialog build()Builds the input dialog.- Returns:
- input dialog
-