0

onOpen EventListener lost on Treeitem

asked 2012-08-08 10:23:59 +0800

cocoes gravatar image cocoes flag of Spain
94 6

Hi,

I'm working with dynamically updated Tree and TreeitemRenderer, and ZK 6.0.2

It seems to me that after updating Treeitem's value with the new DefaultTreeNode and it's node's data, the onOpen event listener that I previously added to the Treeitem seems to be "lost in space": the treeitem says that the listener is avaliable but it's not executed any more.

Curiously, the onRightClick works perfectly, but the onOpen doesn't work if the row has been updated more than once, even if the event listeners are added on the same way.

Sample code

	public void render(Treeitem treeItem, Object data, int arg2) throws Exception {

		DefaultTreeNode treeNode = (DefaultTreeNode) data;
		treeItem.setValue(treeNode);
		Treerow tr = treeItem.getTreerow();
		if(tr == null) {
		    tr = new Treerow();
		} else {
		    tr.getChildren().clear();
		}		
		treeItem.appendChild(tr);		
		MyRowData row = (MyRowData)treeNode.getData();
		tr.appendChild(new Treecell());
                // Add my information to the row...
		
		if (!row.isLeaf())) {
			if (!treeItem.isListenerAvailable(Events.ON_OPEN, true)) { 
				treeItem.addEventListener(Events.ON_OPEN, new EventListener() { 
					public void onEvent(Event event) throws Exception {
						Treeitem ti=(Treeitem)event.getTarget();
						DefaultTreeNode dtn=(DefaultTreeNode)ti.getValue();
						MyRowData row = (MyRowData )dtn.getData();
						row.setOpen(((OpenEvent)event).isOpen());
					}
				}); 			
				treeItem.addEventListener(Events.ON_RIGHT_CLICK, new EventListener() { 
					public void onEvent(Event event) throws Exception {
						((Treeitem)event.getTarget()).setSelected(true);
					}
				});
			}
			
			if (tr.getContext()==null) {
				Menupopup popup=new Menupopup();
				popup.setPage(treeItem.getPage());
				popup.setWidth("300px");
	
                                // Add some menus
				Menuitem mnc=new Menuitem("MyMenu");
				mnc.setImage("/images/myimage.gif");
				ComponentsCtrl.applyForward(mnc, "myid.onClick");
				popup.appendChild(mnc);
				
				tr.setContext(popup);
			}
		}
		treeItem.setOpen(row.isOpen()); 
	}

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2012-08-08 11:24:51 +0800

cocoes gravatar image cocoes flag of Spain
94 6

I've also introduced the org.zkoss.zk.ui.EventListener.duplicateIgnored property on zk.xml, and it doesn't changes the problem.

I've also added a new event listener at the same point as onOpen, (onDoubleClick) and it also works, but not the onOpen.

Any idea?

link publish delete flag offensive edit

answered 2012-09-13 08:53:57 +0800

paowang gravatar image paowang
140 6

Can you provide more code for reproducing?

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-08-08 10:23:59 +0800

Seen: 110 times

Last updated: Sep 13 '12

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