3.5.5.2.11. RefreshAction

RefreshAction 是 列表操作 设计用来为表格或者树组件重新加载数据容器。

该操作通过 com.haulmont.cuba.gui.actions.list.RefreshAction 类实现,在 XML 中需要使用操作属性 type="refresh" 定义。可以用 action 元素的 XML 属性定义通用的操作参数,参阅 声明式操作 了解细节。

如果需要在该操作执行前做一些检查或者与用户做一些交互,可以订阅操作的 ActionPerformedEvent 事件并按需调用操作的 execute() 方法。操作会使用你为它定义的所有参数进行调用。下面的例子中,我们在执行操作前展示了一个确认对话框:

  1. @Named("customersTable.refresh")
  2. private RefreshAction customersTableRefresh;
  3. @Subscribe("customersTable.refresh")
  4. public void onCustomersTableRefresh(Action.ActionPerformedEvent event) {
  5. dialogs.createOptionDialog()
  6. .withCaption("Please confirm")
  7. .withMessage("Are you sure you want to refresh the list?")
  8. .withActions(
  9. new DialogAction(DialogAction.Type.YES)
  10. .withHandler(e -> customersTableRefresh.execute()), // execute action
  11. new DialogAction(DialogAction.Type.NO)
  12. )
  13. .show();
  14. }

另外,还可以先订阅 ActionPerformedEvent,但是不调用操作的 execute() 方法,而是直接出发数据加载器。示例:

  1. @Inject
  2. private CollectionLoader<Customer> customersDl;
  3. @Subscribe("customersTable.refresh")
  4. public void onCustomersTableRefresh(Action.ActionPerformedEvent event) {
  5. customersDl.load();
  6. }