Reputation: 686
I have defined a custom Command in ZK and want to call it by clicking on a Menu Item.
I see that we can define a AuRequest object, but can't find a way to send this AuRequest like we do in JavaScript using zkau.send function.
is something possible at all? If not, is it possible to define the zkau.send in a JavaScript function and call it in 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");
}
}
register the command:
<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>
and MenuItem Event
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??
}
});
Upvotes: 0
Views: 3145
Reputation: 5803
I can't comment on the use of the Command
or AuRequest
objects as you're suggesting here. I've never seen them used and have never used them myself. If there is a way to use them to solve this problem, hopefully you will get an answer. That said, there are other ways to achieve what you are looking to do.
As detailed in the Event Firing section of the Developer Reference, you can fire an event from the static Events
object.
Events.postEvent("onMenuEdit", myTree, myDataEgTheTreeItem);
or..
Events.sendEvent("onMenuEdit", myTree, myDataEgTheTreeItem);
or..
Events.echoEvent("onMenuEdit", myTree, myDataEgTheTreeItem);
Any of these can be handled in a Composer
using..
@Listen("onMenuItem = #myTree")
public void onTreeMenuItemEvent(Event event) {
// Handle event
}
Hope that helps.
Upvotes: 2