2013-03-01 114 views
0

我已经在ZK中定义了一个自定义命令,并且想通过单击菜单项来调用它。来自Java API的ZK火灾事件

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

是有可能的吗?如果没有,是否可以在JavaScript函数中定义zkau.send并在MeunItem中单击事件?

 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.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?? 
      } 
     }); 

回答

2

因为你是在暗示我在这里不能使用CommandAuRequest对象的意见。我从来没有见过他们使用过,并且从未使用过他们。如果有办法用它们来解决这个问题,希望你能得到答案。也就是说,还有其他方法可以实现您期望的目标。

如开发人员参考的Event Firing部分中详细描述的,您可以从静态Events对象触发事件。

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

或..

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

或..

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

任何这些可以使用Composer处理..

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

希望有所帮助。