如何写 可以追踪表格选中状态,仅选中一条记录可用的action

如何写 可以追踪表格选中状态,仅选中一条记录可用的action,我这样写的,还是有点问题的,
image

你好,可以自定义一个action继承自 SecuredListDataComponentAction,这个抽象action是只有选中记录才会启用的操作。

package com.company.jmix2.action;

import io.jmix.core.Messages;
import io.jmix.flowui.action.ActionType;
import io.jmix.flowui.action.list.SecuredListDataComponentAction;
import org.springframework.beans.factory.annotation.Autowired;

@ActionType(ViewHistoryAction.ID)
public class ViewHistoryAction<E> extends SecuredListDataComponentAction<ViewHistoryAction<E>,E> {

    public static final String ID = "list_view_history";

    protected Messages messages;

    public ViewHistoryAction() {
        this(ID);
    }

    public ViewHistoryAction(String id) {
        super(id);
    }

    @Override
    protected void initAction() {
        super.initAction();
    }

    @Autowired
    protected void setMessages(Messages messages) {
        this.messages = messages;
        this.text = messages.getMessage("viewHis");
    }

    @Override
    public void execute() {
        checkTarget();
        target.getSingleSelectedItem();
        System.out.println(target.getSingleSelectedItem().toString());
    }
}

然后在xml使用:

<hbox id="buttonsPanel" classNames="buttons-panel">
...
    <button id="viewHisBtn" action="productsesDataGrid.viewHis"/>
...
</hbox>
<dataGrid id="productsesDataGrid"
          width="100%"
          minHeight="20em"
          dataContainer="productsesDc">
    <actions>
...
        <action id="viewHis" type="list_view_history"/>
    </actions>
...
</dataGrid>

非常感谢