Here's a basic treeview component i use (The backing models contain TreeNode
objects)
I made it abstract so the implementors just provide the fragment or panels
that represent nodes.
TreeView.java :
public abstract class TreeView extends Panel {
public TreeView(String markupId, final IModel rootNodeModel) {
super(markupId, rootNodeModel);
add(new TreeNodeView("node", rootNodeModel));
}
protected abstract Component newComponentForTreeNodeDescription(ListItem
markupContainer, String markupId, TreeNode treeNode);
protected abstract Component newComponentForTreeNodeChildren(ListItem
markupContainer, String markupId, TreeNode treeNode);
private class TreeNodeView extends ListView {
public TreeNodeView(String markupId, final IModel treeNodeModel) {
super(markupId, new LoadableDetachableModel() {
protected Object load() {
TreeNode node = (TreeNode)treeNodeModel.getObject();
List children = node.getChildren();
return children;
};
});
}
@Override
protected void populateItem(ListItem item) {
TreeNode currentChild = (TreeNode)item.getModelObject();
item.setOutputMarkupId(true);
item.add(newComponentForTreeNodeDescription(item, "node_desc",
currentChild));
item.add(newComponentForTreeNodeChildren(item, "children",
currentChild));
}
}
}
TreeView.html :
<wicket:panel>
<li wicket:id="node">
<ul wicket:id="children">
</ul>
</li>
<wicket:child/>
</wicket:panel>
Stefan Selariu-2 wrote:
>
> Hi guys!
>
> I need to make generate something like this dynamically:
>
> <div wicket:id="level1"> <!-- node component -->
> <div> <!-- caption -->
>
> </div>
> <div style="margin-left: 24px;"> <!-- children -->
> <div wicket:id="level2-1"> <!-- node component -->
> <div> <!-- caption -->
> # select
> </div>
> <div style="margin-left: 24px;"> <!-- children -->
> <div wicket:id="level3"> <!-- node component -->
> <div> <!-- caption -->
>
> </div>
> <div style="margin-left: 24px;"> <!-- children -->
> </div>
> </div>
> </div>
> </div>
> <div wicket:id="level2-2"> <!-- node component -->
> <div> <!-- caption -->
>
> </div>
> <div style="margin-left: 24px;"> <!-- children -->
> </div>
> </div>
> </div>
> </div>
>
> This is a tree for which every node has a caption and children.
> Can I create a wicket component for the tree node that supports my
> example?
>
> I need a component that behaves like the Loop but in a recursive way :)
>
> Best regards,
> Stefan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
View this message in context:
http://www.nabble.com/recursive-component-tp17645117p17646533.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]