0

tree node problem zk 5.0.7

asked 2011-06-01 03:22:01 +0800

erlangga gravatar image erlangga
64 1

updated 2011-06-01 03:26:45 +0800

Hi all,

I recently updated my zk version to 5.0.7 and i find out that my Tree component that i use doesn't render the node as it was in 5.0.6.
the tree renders every node under the root, but the tree only renders the first items for every node after.
this is my code for creating the menuItem list

...
        private void createMenu(ApplicationMenu appMenu){
		final List<MenuItem> menuList = appMenu == null ? null : appMenu.getMenuList();
		if(menuList != null && !menuList.isEmpty()){
			
			List <DefaultTreeNode> children = createMenu(menuList);
			DefaultTreeNode root = new DefaultTreeNode("ROOT", children);
			
			DefaultTreeModel treeModel = new DefaultTreeModel(root);
			menuTree.setModel(treeModel);
		}
		
	}

	private List<DefaultTreeNode> createMenu(List<MenuItem> children){
		List<DefaultTreeNode> childrenList = new ArrayList<DefaultTreeNode>();
		if(children != null && !children.isEmpty()){
			for(MenuItem menuItem : children){
				DefaultTreeNode node = new DefaultTreeNode(menuItem, createMenu(menuItem.getChildren()));
				childrenList.add(node);
			}
		}
		
		return childrenList;
	}
...

this is my treeRenderer

          private class MenuTreeitemRenderer implements TreeitemRenderer, Serializable{

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		@Override
		public void render(Treeitem item, Object data) throws Exception {
			DefaultTreeNode node = (DefaultTreeNode)data;
			MenuItem menuItem = (MenuItem)node.getData();
			item.setOpen(false);
			//item.setLabel(CommonFns.getLabel(menuItem.getLabel()));
			item.setLabel(menuItem.getLabel());
			item.setImage(menuItem.getIcon());
			item.setValue(menuItem);
		}		
	}

and this is the MenuItem class

public class MenuItem implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	static int ROOT_ID = 0;
	private UUID id;
	private String label;
	private String icon;
	private String file;
	private String title;
	private MenuItem parent;
	private List<MenuItem> children = new ArrayList<MenuItem>();
	
	public MenuItem(UUID id, String label, String title, String icon, String file, List<MenuItem> children, MenuItem parent){
		this.id = id;
		this.label = label;
		this.setTitle(title);
		this.icon = icon;
		this.file = file;
		if(children != null){
			this.children = children;
		}
		this.parent = parent;
	}
	
	public MenuItem(UUID id, String label, String title, String icon, String file, List<MenuItem> children){
		this.id = id;
		this.label = label;
		this.setTitle(title);
		this.icon = icon;
		this.file = file;
		if(children != null){
			this.children = children;
		}
	}
	
	public MenuItem(UUID uuid, String label, String title, String icon, String file){
		this(uuid, label, title, icon, file, null);
	}
	public UUID getId() {
		return id;
	}
	public void setId(UUID id) {
		this.id = id;
	}
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}
	public String getIcon() {
		return icon;
	}
	public void setIcon(String icon) {
		this.icon = icon;
	}
	public void setFile(String file) {
		this.file = file;
	}
	public String getFile() {
		return file;
	}
	
	public void setTitle(String title) {
		this.title = title;
	}

	public String getTitle() {
		return title;
	}

	public List<MenuItem> getChildren(){
		return children;
	}

	public boolean isCategory(){
		return !(children == null || children.size() == 0);
	}
	
	public void add(MenuItem item){
		children.add(item);
	}
	
	public boolean remove(MenuItem item){
		return children.remove(item);
	}

	public void setParent(MenuItem parent) {
		this.parent = parent;
	}

	public MenuItem getParent() {
		return parent;
	}
}

example result in 5.0.7

list content:
-MenuItem1
  -MenuItem1.1
  -MenuItem1.2
-MenuItem2
  -MenuItem2.1
  -MenuItem2.2

result in tree:
-MenuItem1
   -MenuItem1.1
-MenuItem2
   -MenuItem2.1

if I change the zk version to 5.0.6, all the menuItems are rendered correctly.
is this a bug, or is my implementation wrong?
any help would be appreciated.
thank you and regards,

erlangga

delete flag offensive retag edit

10 Replies

Sort by ยป oldest newest

answered 2011-06-06 22:46:17 +0800

erlangga gravatar image erlangga
64 1

can anyone help me with this?
thank you

link publish delete flag offensive edit

answered 2011-06-08 08:36:31 +0800

hendytoya gravatar image hendytoya
6

same problem. is there anyone got the problem as us?

thanks.

link publish delete flag offensive edit

answered 2011-06-08 19:05:07 +0800

valmar gravatar image valmar
925 2 13
http://www.timo-ernst.net

updated 2011-06-08 19:05:58 +0800

Tree seems to be very buggy since 5.0.6 and 5.0.7.

See: http://www.zkoss.org/forum/listComment/16400 and http://www.zkoss.org/forum/listComment/16403

I think it's not your fault but rather a problem with the new ZK upgrades.

I am currently thinking about going back to ZK 5.0.5 if these problems persist.

link publish delete flag offensive edit

answered 2011-06-09 05:23:38 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

I have tested with the following sample and ZK 5.0.7.1

<zk>
	<zscript><![CDATA[
		import java.util.*;
		import org.zkoss.zul.*;
		
		TreeModel model = new DefaultTreeModel(
			new DefaultTreeNode(null, new DefaultTreeNode[] {
	      		new DefaultTreeNode("item 0", new DefaultTreeNode[] {
	          		new DefaultTreeNode("item 00"),new DefaultTreeNode("item 01")
	          	}),
	          	new DefaultTreeNode("item 1", new DefaultTreeNode[] {
	          		new DefaultTreeNode("item 10"),new DefaultTreeNode("item 11")
	          	}),
	          	new DefaultTreeNode("item 2", new ArrayList())
			})
		);
		
		
		TreeitemRenderer renderer = new TreeitemRenderer() {
		    public void render(Treeitem item, Object data) throws Exception {
		    	TreeNode node = (TreeNode) data;
		        item.setLabel(node.getData().toString());
		    }
		};
	]]></zscript>
	<tree width="300px" itemRenderer="${renderer}" model="${model}"/>
</zk>

it works fine.

link publish delete flag offensive edit

answered 2011-06-09 07:09:45 +0800

erlangga gravatar image erlangga
64 1

hi Jimmy,

yes, i have tried that scenario too, and it does worked well.
I debugged my code and found out that in the Tree class, before the renderChildren method in renderItem0, DefaultTreeNode had all the items that I put in there.

any enlightment to this condition?

thanks

link publish delete flag offensive edit

answered 2011-06-09 21:20:08 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

I have tried another sample

<zk>
	<zscript><![CDATA[
		import java.util.*;
		import org.zkoss.zul.*;
		import org.zkoss.util.CollectionsX.ArrayCollection;
		
		Map data = new HashMap();		
		data.put("item 0", new String[]{"item 00","item 01"});
		data.put("item 1", new String[]{"item 10","item 11"});
		

		public List createMenu(Collection children){
			List childrenList = new ArrayList();
			if(children != null && !children.isEmpty()){
				if (children instanceof Set) {
					for (Object o: children) {
						Map.Entry entry = (Map.Entry) o;
						childrenList.add(new DefaultTreeNode(entry.getKey(), 
								createMenu(new ArrayCollection((String[]) entry.getValue()))));
					}
				} else {
					for (Object o: children) {
						childrenList.add(new DefaultTreeNode(o.toString()));
					}
				}
			}
			
			return childrenList;
		}
		
		DefaultTreeModel model = 
			new DefaultTreeModel(new DefaultTreeNode("ROOT", createMenu(data.entrySet())));
		
		
		TreeitemRenderer renderer = new TreeitemRenderer() {
		    public void render(Treeitem item, Object data) throws Exception {
		    	TreeNode node = (TreeNode) data;
		        item.setLabel(node.getData().toString());
		    }
		};
	]]></zscript>
	<tree width="300px" itemRenderer="${renderer}" model="${model}"/>
</zk>

can you try to print all of children in the model?

link publish delete flag offensive edit

answered 2011-06-09 21:42:42 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

BTW, we release zk fiddle
the sample in here
http://zkfiddle.org/sample/31s8vtg/2
Can you provide your sample in zk fiddle?

link publish delete flag offensive edit

answered 2011-06-10 06:14:40 +0800

erlangga gravatar image erlangga
64 1

i have tried to create a new zk project to try and reproduce this issue. but for some reason I cannot. it works fine.
then i tried to use a manually created list to supply the model. when i put it in the new project, it works fine, but when i put it in my old project this issue shows.

both project use zk 5.0.7.1, but my old project one uses maven, and the new one doesn't.

any idea?

as for zkfiddle, since i cannot reproduce the issue, i can't put my code in it, my old project is a bit complicated and involves many classes.

thank you.

link publish delete flag offensive edit

answered 2011-06-10 06:39:57 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Only a hint.

Maven does not load the zk dependend files which are stored behind the /WEB-INF folder like

WEB-INF/tld
WEB-INF/xsd

I have exported an upgraded project as .war-file. I'm wondering why the design of that exported application lacks. All the 3d mold gradient background pictures are not shown.
By manually copy these version dependend files all is runing well.

link publish delete flag offensive edit

answered 2012-02-09 06:04:54 +0800

isisis gravatar image isisis
18

Hi,

I think the problem is when you try to call setOpen when treenode is rendering.

 private class MenuTreeitemRenderer implements TreeitemRenderer, Serializable{

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		@Override
		public void render(Treeitem item, Object data) throws Exception {
			DefaultTreeNode node = (DefaultTreeNode)data;
			MenuItem menuItem = (MenuItem)node.getData();
			item.setOpen(false);
			//item.setLabel(CommonFns.getLabel(menuItem.getLabel()));
			item.setLabel(menuItem.getLabel());
			item.setImage(menuItem.getIcon());
			item.setValue(menuItem);
		}		
	}

I change the code to :

private class MenuTreeitemRenderer implements TreeitemRenderer, Serializable{

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		@Override
		public void render(Treeitem item, Object data) throws Exception {
			DefaultTreeNode node = (DefaultTreeNode)data;
			MenuItem menuItem = (MenuItem)node.getData();
			item.setOpen(true);
			item.setLabel(menuItem.getLabel());
			item.setImage(menuItem.getIcon());
			item.setValue(menuItem);			
			Treerow row = item.getTreerow();				
			row.addEventListener(Events.ON_CLICK, MenuPanel.this);
			item.setOpen(false);
		}		
	}

And it's work properly now.
I don't know if this a bug in zk or not.
I am using zk 5.0.10.

FYI, I am in the same team with erlangga and hendytoya..:D

Thanks!!

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: 2011-06-01 03:22:01 +0800

Seen: 813 times

Last updated: Feb 09 '12

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