清空值

EntityClearAction 是一个值选择器操作,用来清空 ValuePicker 的值。

该操作通过 io.jmix.ui.action.valuepicker.ValueClearAction 类实现,在 XML 中需要使用操作属性 type="value_clear" 定义。可以用 action 元素的 XML 属性定义通用的操作参数,参阅 声明式操作 了解细节。

使用 ActionPerformedEvent

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

@Named("valuePicker.clear")
private ValueClearAction valuePickerClear;

@Subscribe("valuePicker.clear")
public void onValuePickerClear(Action.ActionPerformedEvent event) {
    dialogs.createOptionDialog()
            .withCaption("Please confirm")
            .withMessage("Do you really want to clear the field?")
            .withActions(
                    new DialogAction(DialogAction.Type.YES)
                            .withHandler(e -> valuePickerClear.execute()), // execute action
                    new DialogAction(DialogAction.Type.NO)
            )
            .show();
}