2.2. Running Reports from Screens

You can run reports from arbitrary screens using special actions and associated buttons or component context menu items. In such case report availability in this screen will also be checked in addition to user role.

Action types and examples of their use are provided below.

  • com.haulmont.reports.gui.actions.RunReportAction - action showing the list of all available reports. When a user selects a report from the list, the parameters input form is displayed (if any were defined) and the report is run.

    Below is an example of using the action together with a button declared in the screen XML descriptor:

    • XML-descriptor

      <layout>
          <table id="bookTable">
              ...
              <buttonsPanel id="buttonsPanel">
                  ...
                  <button id="reportButton"
                          icon="icons/reports-print.png"/>
              </buttonsPanel>
          </table>
    • Controller

      @Inject
      private Button reportButton;
      
      @Override
      public void init(Map<String, Object> params) {
          reportButton.setAction(new RunReportAction("report"));
      }
    • messages.properties

      report = Report
  • com.haulmont.reports.gui.actions.TablePrintFormAction - an action associated with a table displaying a list of entity instances. 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 table. 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 table is passed into it.

    • If the parameter has the Entity type, and the table 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 table 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 action in a button and the table context menu:

    • XML descriptor

      <layout>
          <table id="bookTable">
              ...
              <buttonsPanel id="buttonsPanel">
                  ...
                  <button id="reportButton"
                          icon="icons/reports-print.png"/>
              </buttonsPanel>
          </table>
    • Controller

      @Inject
      private Button reportButton;
      
      @Inject
      private Table bookTable;
      
      @Override
      public void init(Map<String, Object> params) {
          TablePrintFormAction action = new TablePrintFormAction("report", bookTable);
          bookTable.addAction(action);
          reportButton.setAction(action);
      }
    • messages.properties

      report = Report
  • 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="windowActionsBox">
          ...
          <hbox id="windowActionsBox"
                spacing="true">
              <iframe id="windowActions"
                      screen="editWindowActions"/>
              <button id="reportButton"/>
          </hbox>
      </layout>
    • Controller

      @Inject
      private Button reportButton;
      
      @Override
      public void init(Map<String, Object> params) {
          reportButton.setAction(new EditorPrintFormAction("report", this, null));
      }
    • messages.properties

      report = Report