0

我在 ZK 中定义了一个自定义命令,并希望通过单击菜单项来调用它。

我看到我们可以定义一个 AuRequest 对象,但是找不到像我们在 JavaScript 中使用 zkau.send 函数那样发送这个 AuRequest 的方法。

有什么可能吗?如果没有,是否可以在 JavaScript 函数中定义 zkau.send 并在 MeunItem Click Event 中调用它?

     public class MyCustomCommand extends Command
     {
        protected MyCustomCommand(final String id, final int flags)
        {
            super(id, flags);
        }

        @Override
        protected void process(final AuRequest request)
        {
            System.out.println("Menu Item Click");
        }

     }

注册命令:

<bean id="myCustomCommand" class="com.test.commands.MyCustomCommand">
    <constructor-arg value="onMenuEdit" />
    <constructor-arg><util:constant static-field="org.zkoss.zk.au.Command.IGNORE_OLD_EQUIV"/></constructor-arg>
</bean>

和 MenuItem 事件

        menuItem.addEventListener(Events.ON_CLICK, new EventListener()
        {
            @Override
            public void onEvent(final Event event) throws Exception
            {

                final Tree tree = (Tree) parent;
                final Treeitem treeitem = tree.getSelectedItem();

                final AuRequest auRequest = new AuRequest(treeitem.getDesktop(), treeitem.getUuid(), "onMenuEdit", new String[]{});

                //how to send the auRequest??
            }
        });
4

1 回答 1

2

正如您在此处建议的那样,我无法评论Commandor对象的使用。AuRequest我从未见过它们被使用过,我自己也从未使用过它们。如果有办法使用它们来解决这个问题,希望你能得到答案。也就是说,还有其他方法可以实现您想要做的事情。

正如开发者参考的事件触发部分所详述的,您可以从静态Events对象触发事件。

Events.postEvent("onMenuEdit", myTree, myDataEgTheTreeItem);

或者..

Events.sendEvent("onMenuEdit", myTree, myDataEgTheTreeItem);

或者..

Events.echoEvent("onMenuEdit", myTree, myDataEgTheTreeItem);

任何这些都可以在Composerusing..

@Listen("onMenuItem = #myTree")
public void onTreeMenuItemEvent(Event event) {
    // Handle event
}

希望有帮助。

于 2013-03-01T19:08:10.597 回答