5.2. 从界面运行报表

可以使用特定操作(action)及相关的按钮或组件右键菜单从任意界面运行报表。在这种情况下,除了用户角色外,还将检查报表在此界面的可用性

下面提供操作(action)类型及其使用示例。

  • com.haulmont.reports.gui.actions.list.RunReportAction - 一个 标准操作 ,展示可用报表列表。需要定义给一个 Button 或者列表组件(TableDataGrid 等)。

    下面是 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 - type 属性定义了一个特殊的 runReport 操作类型,由框架提供。

    使用编程式方法创建操作,该操作关联一个在 XML 描述中声明的按钮,示例:

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

    当操作执行时,会打开一个模态的 Report Run 对话框展示与当前界面相关的报表。当用户从列表中选择一个报表时,会展示参数输入表单(如果有的话),然后会运行报表。

  • com.haulmont.reports.gui.actions.list.ListPrintFormAction – 一个 标准操作 ,用来打印报表,该报表为与列表组件(TableDataGrid 等)关联的实体实例集合。

    此操作只会选择带有外部 Entity 或者 List of entities 类型参数的报表,并且要求参数实体类型符合列表组件展示的实体类型。如果最后筛选结果只有一个报表,则会立即调用。如果有多个报表符合条件,则会展示报表列表交于用户选择。

    使用以下规则将外部参数值传递给报表:

    • 如果参数是 List of entities 类型,会将列表组件中当前选择的实例列表传递给它。

    • 如果参数是 Entity 类型,并且在列表组件选择了单个实例(突出显示一行),则选中实例会传递到报表中。

    • 如果是 Entity 类型的参数,并且列表组件中选择了多行,则报表会根据选择的实例数量运行多次。执行之后,用户将得到一个包含所有生成的报表的 ZIP 文件。

      下面是 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 - type 属性定义了一个特殊的 listPrintForm 操作类型,由框架提供。

      使用编程式方法创建操作,该操作关联一个在 XML 描述中声明的按钮,示例:

      @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);
      }

      当操作执行时,如果列表组件没有选中实体,会显示一个确认窗口。

      run actions listPrint confirmation
      Figure 57. 确认窗口

      之后,会打开一个模态的 Run reports 对话框展示与当前界面相关的报表。从该模态窗口,用户可以针对选中的实体运行报表。

  • com.haulmont.reports.gui.actions.EditorPrintFormAction - 与实体编辑器界面关联的操作。该操作仅选择外部参数类型是 EntityList of entities 的报表,并且参数实体类型要与编辑的实体类型一样。如果只有一个这样的报表,则会立即调用它。如果多个,则会显示一个列表供用户选择。

    外部参数值 - 被编辑的实体实例被传递到报表中。如果参数是 List of entities 类型,则会传递一个包含单个条目的列表。

    下面是在一个按钮中使用这个操作的示例,这个按钮位于标准的 OKCancel 按钮旁边:

    • XML 描述

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

      @Inject
      private Button reportButton;
      
      @Subscribe
      public void onInit(InitEvent event) {
          reportButton.setAction(new EditorPrintFormAction(this,null));
      }
  • com.haulmont.reports.gui.actions.list.ExecutionHistoryAction – 一个 标准操作 ,用来展示报表的 执行历史记录。需要定义给一个 Button 或者列表组件(TableDataGrid 等)。

    要查看报表的执行历史,可以在 Administration > Application Properties 界面设置 reporting.executionHistory.enabled 应用程序属性为 true

    下面是 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 - type 属性定义了一个特殊的 executionHistory 操作类型,由框架提供。

    使用编程式方法创建操作,该操作关联一个在 XML 描述中声明的按钮,示例:

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

    当操作执行时,会打开一个模态的 Execution history 对话框展示与当前界面相关的报表。点击 Execution History 之后,会展示选中报表的执行记录。如果未选中任何报表,则会展示与此界面关联的所有报表的执行记录。