Yeah, that's like Wicket's "nested" example in wicket-examples. Eelco
On Thu, Oct 8, 2009 at 12:27 PM, Ceki Gulcu <c...@qos.ch> wrote: > Hello, > > I just succeeded to create a self-recursive panel displaying a > tree-like structure with less than 40 lines of java code and 10 lines > of HTML. I am including the code here in case someone is interested. > > > ============================================== > public class Node implements Serializable { > > String name; > List<Node> childrenList = new ArrayList<Node>(); > > Node(String name) { > this.name = name; > } > > public void add(Node child) { > childrenList.add(child); > } > > public String getName() { > return name; > } > > public List<Node> getChildrenList() { > return childrenList; > } > > static Node getSampleNode() { > Node nodeA = new Node("A"); > Node nodeA0 = new Node("A0"); > Node nodeA00 = new Node("A00"); > Node nodeA01 = new Node("A01"); > Node nodeA1 = new Node("A1"); > > nodeA.add(nodeA0); > nodeA.add(nodeA1); > > nodeA0.add(nodeA00); > nodeA0.add(nodeA01); > return nodeA; > } > } > > =============== Tree.java and Tree.html ======================== > public class Tree extends WebPage { > > public Tree() { > Node node = Node.getSampleNode(); > NodePanel nodePanel = new NodePanel("", "node", node); > add(nodePanel); > } > } > > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > <title>Tree</title> > <link rel="stylesheet" href="style.css" /> > </head> > <body> > <div wicket:id="node"></div> > </body> > </html> > ================================================================ > > > ===== NodePanel.hava and html ================================== > public class NodePanel extends Panel { > > public NodePanel(final String indent, String id, Node node) { > super(id); > > add(new Label("name", indent+node.getName())); > > if (node.getChildrenList().size() == 0) { > final WebMarkupContainer parent = new WebMarkupContainer("children"); > add(parent); > parent.add(new EmptyPanel("node")); > } else { > add(new ListView("children", node.getChildrenList()) { > �...@override > protected void populateItem(ListItem item) { > Node childNode = (Node) item.getModelObject(); > item.add(new NodePanel(indent+"----", "node", childNode)); > } > }); > } > } > } > > <html xmlns:wicket> > > <wicket:panel> > <p wicket:id="name">name</p> > > <div wicket:id="children"> > <div wicket:id="node"> > </div> > </div> > </wicket:panel> > > </html> > ================================================================ > > HTH, > > -- > Ceki Gülcü > Logback: The reliable, generic, fast and flexible logging framework for > Java. > http://logback.qos.ch > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org