移除
属性
下列参数可以在 XML 或 Java 中设置:
- 
confirmation- 布尔值,配置是否需要在移除选中实体之前展示确认对话框。默认为true。
- 
confirmationMessage- 确认窗口的消息。默认从主消息包的dialogs.Confirmation.Remove键值获取。
- 
confirmationTitle- 确认窗口标题。默认从主消息包的dialogs.Confirmation键值获取。
比如,希望展示特殊的确认消息,可以在 XML 中如下配置:
<action id="exclude" type="exclude">
    <properties>
        <property name="confirmation" value="true"/>
        <property name="confirmationTitle" value="Removing brand..."/>
        <property name="confirmationMessage"
                  value="Do you really want to remove the brand from the list?"/>
    </properties>
</action>或者,可以在界面控制器注入该操作,然后用 setter 配置:
@Named("brandsTable.exclude")
private ExcludeAction<Brand> excludeAction;
@Subscribe
public void onInitEntity(InitEntityEvent<Customer> event) {
    excludeAction.setConfirmation(true);
    excludeAction.setConfirmationTitle("Removing brand...");
    excludeAction.setConfirmationMessage("Do you really want to remove the brand from the list?");
}处理器
下面了解这些只能用 Java 配置的参数。用 Studio 能为这些参数正确生成带注解的方法。
afterActionPerformedHandler
在选中实体移除之后调用。接收 event 对象作为参数,可以用来获取要移除的实体。示例:
@Install(to = "brandsTable.exclude", subject = "afterActionPerformedHandler")
private void brandsTableExcludeAfterActionPerformedHandler(RemoveOperation.AfterActionPerformedEvent<Brand> event) {
    System.out.println("Removed " + event.getItems());
}使用 ActionPerformedEvent
如果需要在该操作执行前做一些检查或者与用户做一些交互,可以订阅操作的 ActionPerformedEvent 事件并按需调用操作的 execute() 方法。操作会使用你为它定义的所有参数进行调用。下面的例子中,我们在执行操作前展示了一个自定义对话框:
@Subscribe("brandsTable.exclude")
public void onBrandsTableExclude(Action.ActionPerformedEvent event) {
    excludeAction.setConfirmation(false);
    dialogs.createOptionDialog()
            .withCaption("My confirm dialog")
            .withMessage("Do you really want to remove the brand from the list?")
            .withActions(
                    new DialogAction(DialogAction.Type.YES)
                            .withHandler(e -> excludeAction.execute()), // execute action
                    new DialogAction(DialogAction.Type.NO)
            )
            .show();
}另外,还可以先订阅 ActionPerformedEvent,但是不调用操作的 execute() 方法,而是使用 RemoveOperation API 直接移除选择的实体。此时,会忽略所有特殊的操作参数和行为,只能用其通用参数,比如 caption、icon 等。示例:
@Autowired
private RemoveOperation removeOperation;
@Subscribe("brandsTable.excludeAction")
public void onBrandsTableExcludeAction(Action.ActionPerformedEvent event) {
    removeOperation.builder(brandsTable)
            .withConfirmationMessage("Do you really want to remove the brand from the list?")
            .withConfirmationTitle("Removing brand...")
            .exclude();
}本页是否有帮助?
        
        
    感谢您的反馈