5.2. Running Reports from Screens

You can run reports from arbitrary screens using special actions and associated buttons or component context menu items. In this case, the availability of the report directly in this screen is checked in addition to a user role.

Action types and examples of their use are provided below.

  • com.haulmont.reports.gui.actions.list.RunReportAction – a standard action that displays the list of all available reports. It should be defined for a Button or a list component (Table, DataGrid, etc.).

    Below is an example of using the declarative action for the GroupTable:

    <groupTable id="booksTable"
                width="100%"
                dataContainer="booksDc">
        <actions>
            <action id="create" type="create"/>
            <action id="edit" type="edit"/>
            <action id="remove" type="remove"/>
            <action id="run" type="runReport"/> (1)
        </actions>
        <columns>
            <!-- -->
        </columns>
        <rowsCount/>
        <buttonsPanel id="buttonsPanel"
                      alwaysVisible="true">
            <!-- -->
            <button id="runBtn" action="booksTable.run"/>
        </buttonsPanel>
    </groupTable>
    1 - the type attribute defines a specific runReport action type, provided by the framework.

    Example of programmatically creating the action together with a button declared in the screen XML descriptor:

    @Inject
    protected Actions actions;
    
    @Inject
    protected Button runReportBtn;
    
    @Subscribe
    public void onInit(InitEvent event) {
        Action runReportAction = actions.create(RunReportAction.class, "runReport");
        runReportBtn.setAction(runReportAction);
    }

    When the action is performed, a modal Report Run dialog will open where reports related to the current screen will be displayed. When a user selects a report from the list, the parameters input form is displayed (if any were defined) and the report is run.

  • com.haulmont.reports.gui.actions.list.ListPrintFormAction – a standard action for printing reports for entity instances associated with a list component (Table, DataGrid, etc.).

    The action only selects reports having an external parameter of the Entity or the List of entities type and where the parameter entity type matches the entity type displayed by the list component. If only one report is available as a result of selection, it is invoked immediately. If several reports are available, their list is offered to the user for selection.

    The external parameter value is passed to the report using the following rules:

    • If the parameter has the List of entities type, the list of instances currently selected in the list component is passed into it.

    • If the parameter has the Entity type, and the list component has a single instance selected (one row is highlighted), then this instance is passed into the report.

    • If the parameter is of the Entity type, and the list component has several rows selected, then the report runs several times according to the number of selected instances. After execution, the user gets a single ZIP archive containing all generated reports.

      Below is an example of using the declarative action for the GroupTable:

      <groupTable id="authorsTable"
                  width="100%"
                  dataContainer="authorsDc">
          <actions>
              <action id="create" type="create"/>
              <action id="edit" type="edit"/>
              <action id="remove" type="remove"/>
              <action id="list" type="listPrintForm"/> (1)
          </actions>
          <columns>
              <!-- -->
          </columns>
          <rowsCount/>
          <buttonsPanel id="buttonsPanel"
                        alwaysVisible="true">
              <!-- -->
              <button id="listBtn" action="authorsTable.list"/>
          </buttonsPanel>
      </groupTable>
      1 - the type attribute defines a specific listPrintForm action type, provided by the framework.

      Example of programmatically creating the action together with a button declared in the screen XML descriptor:

      @Inject
      protected Actions actions;
      
      @Inject
      protected Button listPrintBtn;
      
      @Inject
      private GroupTable<Author> authorsTable;
      
      @Subscribe
      public void onInit(InitEvent event) {
          Action listPrintFormAction = actions.create(ListPrintFormAction.class, "listPrintFormAction");
          authorsTable.addAction(listPrintFormAction);
          listPrintBtn.setAction(listPrintFormAction);
      }

      When the action is performed, if no entities were selected from the list component, a confirmation window will be displayed.

      run actions listPrint confirmation
      Figure 58. A confirmation window

      After that, the modal Run reports dialog will open where reports related to the current screen will be displayed. From this modal screen, the user can run some report for the selected entity.

  • com.haulmont.reports.gui.actions.EditorPrintFormAction – an action associated with an entity editor screen. The action only selects reports having an external parameter of the Entity or the List of entities type and where the parameter entity type matches the edited entity type. If only one report is available as a result of selection, it is invoked immediately. If several reports are available, their list is offered to user for selection.

    The external parameter value – edited entity instance – is passed into the report. If the parameter has the List of entities type, then a list containing a single item is passed.

    Below is an example of using the action in a button located near the standard OK and Cancel buttons:

    • XML descriptor

      <layout expand="editActions" spacing="true">
          <!--...-->
          <hbox id="editActions" spacing="true">
              <button action="windowCommitAndClose"/>
              <button action="windowClose"/>
              <button id="reportButton" icon="PRINT"/>
          </hbox>
      </layout>
    • Controller

      @Inject
      private Button reportButton;
      
      @Subscribe
      public void onInit(InitEvent event) {
          reportButton.setAction(new EditorPrintFormAction(this,null));
      }
  • com.haulmont.reports.gui.actions.list.ExecutionHistoryAction – a standard action for displaying the report execution history. It should be defined for a Button or a list component (Table, DataGrid, etc.).

    To view the report execution history set the reporting.executionHistory.enabled application property to true in the Administration > Application Properties screen.

    Below is an example of using the declarative action for the GroupTable:

    <groupTable id="authorsTable"
                width="100%"
                dataContainer="authorsDc">
        <actions>
            <action id="create" type="create"/>
            <action id="edit" type="edit"/>
            <action id="remove" type="remove"/>
            <action id="history" type="executionHistory"/> (1)
        </actions>
        <columns>
            <!-- -->
        </columns>
        <rowsCount/>
        <buttonsPanel id="buttonsPanel"
                      alwaysVisible="true">
            <!-- -->
            <button id="historyBtn" action="authorsTable.history"/>
        </buttonsPanel>
    </groupTable>
    1 - the type attribute defines a specific executionHistory action type, provided by the framework.

    Example of programmatically creating the action together with a button declared in the screen XML descriptor:

    @Inject
    protected Actions actions;
    
    @Inject
    protected Button execHistoryBtn;
    
    @Subscribe
    public void onInit(InitEvent event) {
        Action execHistoryAction = actions.create(ExecutionHistoryAction.class, "execHistoryReport");
        execHistoryBtn.setAction(execHistoryAction);
    }

    When the action is performed, a modal Execution history dialog will open where reports related to the current screen will be displayed. After clicking on the Execution History button, the execution history for the selected reports will be displayed. If no reports have been selected, then execution history will be displayed for all reports associated with the screen.