1

Different results when forwarding from Menuitem, Treeitem and Treecell

asked 2013-02-15 16:32:36 +0800

cocoes gravatar image cocoes flag of Spain
94 6

updated 2013-02-19 10:12:57 +0800

Hi!

I'm developing a very complex tool, managed by events and a per-user thread that updates UI very often. I use MVC and a lot of Executions.schedule events all around. I use EE 6.5.1.1.

My current problem is a dinamically generated Tree, where I want to forward to the window listener depending on the column and row that the user "clicks" or "double-clicks". But what works when I forward from a MenuItem added to the tree rows, doesn't works If I try to forward from the Treecell or from the treeitem.

In fact, it has a estrange behaviour, because some times the forward to the window listener doesn't receives the event until an other event happens, like if it's waiting for other events to execute itself.

I've tryed to change the target component of the forward to the main page event listener, but it doesn't helps at all...

It's impossible to reproduce all the application, so I would likt to know if I'm missing anything in the following code:

public void render(Treeitem treeItem, Object data, int arg2) throws Exception {
...
DefaultTreeNode treeNode = (DefaultTreeNode) data;
treeItem.setValue(treeNode);
Treerow tr;
if (treeItem.getTreerow() == null) {
    tr = new Treerow();
    tr.setParent(treeItem);
} else {
    tr = treeItem.getTreerow();
    tr.getChildren().clear();
}
...
Treecell mycell=new Treecell();
Div mydiv=new Div();
mydiv.appendChild(new Label("some text"));
mycell.appendChild(mydiv);
mycell.addEventListener(Events.ON_CLICK, new EventListener() { 
    public void onEvent(Event event) throws Exception {
        // 1. THIS DON'T WORKS
        ComponentsCtrl.applyForward(event.getTarget(), "pageid.onMyMethod");
    }
});
tr.appendChild(mycell);
...

treeItem.addEventListener(Events.ON_CLICK, new EventListener() { 
    public void onEvent(Event event) throws Exception {
        // 2. THIS DON'T WORKS
        ComponentsCtrl.applyForward(event.getTarget(), "pageid.onMyMethod");
}
});             
...

Menupopup popup=new Menupopup();
popup.setPage(treeItem.getPage());
Menuitem mnc=new Menuitem("Mytitle");
mnc.addEventListener(Events.ON_CLICK , new EventListener() { 
    public void onEvent(Event event) throws Exception {
        // 3. THIS WORKS
        ComponentsCtrl.applyForward(event.getTarget(), "pageid.onMyMethod");
    }
});
popup.appendChild(mnc);
tr.setContext(popup);

@hswain

It took me some time but here it is:

http://zkfiddle.org/sample/2rru3vv/1-Forward-include-and-test-owner-test

To test it just click in the first cell of the first row "1". It will show a messagebox if you click on it, and tryes to forward the event to the main controller listener, but it never does. On the other hand, if you right click on it and execute the menu option "A", it will execute the two messages, the one from the tree renderer right click event, and the message from the main window event listener.

From what I guess, as it is explained here: http://forum.zkoss.org/question/62833/id-spaces-space-owners-for-complex-nested-structures/

, the problem is the include element, that changes the space owner and is not allowing me to do the forward from a treecell inside the include to the main window event listener. But what is curious is that I can do the forward from a right-click menu from the same tree.

I've also tryed getting the component from ComponentsCtrl.applyForward( Path.getComponent("//"), "XXX.onYYY") , but it also doesn't works. I still don't know how to communicate from the event in one of the include's element with the main window with a forward...

Any idea?

Thanks in advance.

delete flag offensive retag edit

Comments

hi can you post your demo in zk Fiddle?

hswain ( 2013-02-15 19:06:20 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-02-20 10:20:16 +0800

cocoes gravatar image cocoes flag of Spain
94 6

updated 2013-02-20 10:25:09 +0800

To share with the community, this is the solution that the ZK team provided to me. It works:

If you wish to forward events across different IdSpaces, you can use a component Path to specify the target component that you would like to forward a specific event to. In this case, just add <?page id="mainPage" ?> to index.zul, and modify ComponentsCtrl.applyForward in TreeRendererTest.java to ComponentsCtrl.applyForward(event.getTarget(), "//mainPage/mypage.onTest1") Please also refer to

http://books.zkoss.org/wiki/ZKDeveloper%27sReference/EventHandling/EventForwarding

#Usingacomponent_Path

The solution is here: http://zkfiddle.org/sample/14r4e8n/2-Forward-include-and-test-owner-test

An other problem that I had that caused double or triple event executions was due to having the same listener method with Event type instead of just having with the ForwardEvent type:

public void onTest1(ForwardEvent forwardEvent){
        Messagebox.show("Hello 1 step 2 FW", "result", Messagebox.OK, Messagebox.INFORMATION);
}

public void onTest1(Event forwardEvent){
        Messagebox.show("Hello 1 step 2 WV", "result", Messagebox.OK, Messagebox.INFORMATION);
}

Regards,

Vicente

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2013-02-15 16:32:36 +0800

Seen: 54 times

Last updated: Feb 20 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More