创建实体数据时如何自动添加选中的父类

已经通过重写 CreateAction 实现了功能,但感觉不优雅,是否可以通过Editor类onInitEntity事件去设置选中的父类呢?这个就需要获取选中的数据

image

当然可以在 onInitEntity 方法中给实体属性赋值。这里关键问题是什么?如何获取选中的数据?

是的,求教 :handshake:

:slight_smile:

  • 也许不需要重写 CreateAction 就可以对弹出的 Edtior 进行配制,参考以下代码:
        CreateAction<Attachment> createAction = (CreateAction<Attachment>) table.getAction("create");
        
        createAction.setScreenConfigurer(screen -> {
            ((AttachmentEdit) screen).getCategoryField().setVisible(true);
            screen.addAfterShowListener(afterShowEvent -> {
                Category currentItem = categoryTree.getSingleSelected();
                ((AttachmentEdit) screen).getCategoryField().setValue(currentItem);
            });
        });
        
  • 获取 TreeTable 的选中项 用 TreeTable.getSingleSelected()
1赞

搞定:handshake:

@Autowired
private lateinit var materialTypesTable: TreeTable<MaterialType>


@Install(to = "materialTypesTable.create", subject = "screenConfigurer")
private fun screenConfigurer(screen: Screen?) {

    screen!!.addAfterShowListener {
        val singleSelected = materialTypesTable.getSingleSelected()

        (screen as MaterialTypeEdit).editedEntity.parent = singleSelected
    }

}