How to open a modal dialog

Normally a dialog is opened in response of a user action.

This is the sample case we are going to describe.


Register the action and its triggering strokes or tags.

      ...
      form.registerAction("newVersionLbl", new NewVersionLblAction());
      ...

Define the class implementing the action.

  ...
  protected class NewVersionLblAction implements IFormAction {

    private static final long serialVersionUID = 1L;

    @Override
    public IFlowState execute(IBndsFlow flow, HttpServletRequest request,
                              String formName, ActionInfo action,
                              Map<String, UploadedFile> files) {
      String msg = "Creating a new version tag ...";
      ...
      return null;
    }

    @Override
    public String getLabel() {
      return "New version tag";
    }

    @Override
    public boolean isEnabled() {
      return ivDs.hasWritePermissions(); 
    }
  }
  ...

In the execute(...) method:

  • Create an instance of the flow used as modal dialog, in this case the one described in How to create a form and validate it.
        final AskForVersionLblDlg dlg = new AskForVersionLblDlg(ivDs.getTagsOf(), msg);
    
  • Use the FlowContext helper class to open the modal dialog
        FlowContext.get().modalDialog(
    
  • The first parameter must be a flow assuming the IFlowAsDialog "personality", ie. call the asDialog(String) method on the flow object.
          dlg.asDialog(null),
    
  • The second parameter is a class implementing the IDialogCallback interface, it contains the code executed when the modal dialog is closed.
          new IDialogCallback() {
            private static final long serialVersionUID = 1L;
            @Override
            public IFlowState endDialog(IFlow flow,
                                      IFlowAsDialog dialog, IFlowEndState res) {
              if (res != DialogResultEnum.OK)
                return null;
              ...  // go on, you can even open a new modal-dialog
              return null;
            }
          }
        );
    

    NOTE: The dialog call-back code can switch the state of the flow where the opening dialog action has been executed by returning the IFlowState to switch to instead of null.