I’d used Tree component(id=”tree”)
as navigation layout, I want to change another panel component(id=”main”)
of the same layout when one tree node clicked, But nothing change occur. When I
use the link component to change the same panel component(id=”main”)
followed the nested demo of wicket-example, so it’s ok! Oh, how can I get
the same effect use Tree component??? All files associated: BasePage.java public class BasePage extends WebPage{ public BasePage() { add(new
TreePanel("tree",null)); add(new
MainPanel("main",new Model("Begin"))); } } BasePage.html <html> <head> <title>test</title> <link rel="stylesheet" type="text/css" href=""> </head> <body> <div> <span
wicket:id="tree">[tree here]</span> <span
wicket:id="main">[main here]</span> </div> <div id="body"> <wicket:child /> </div> </body> </html> TreePanel.java public class TreePanel extends Panel{ public TreePanel(String s, IModel
iModel) { super(s,
iModel); add(tree); } private Tree tree=new
Tree("tree", createTreeModel()) { protected
String renderNode(TreeNode node) { ModelBean
bean = (ModelBean) ((DefaultMutableTreeNode)node).getUserObject(); return
bean.getProperty1(); }
protected void onNodeLinkClicked(AjaxRequestTarget ajaxRequestTarget, TreeNode
treeNode){
ModelBean bean = (ModelBean)
((DefaultMutableTreeNode)treeNode).getUserObject();
//followed line I want to get the
effect, but I failed!
this.getParent().getPage().replace(new MainPanel("main",new
Model(bean.getProperty1())));
} }; /** *
Creates the model that feeds the tree. *
@return *
New
instance of tree model. */ protected
TreeModel createTreeModel() { List
l1 = new ArrayList(); l1.add("test
1.1"); l1.add("test
1.2"); l1.add("test
1.3"); List
l2 = new ArrayList(); l2.add("test
2.1"); l2.add("test
2.2"); l2.add("test
2.3"); List
l3 = new ArrayList(); l3.add("test
3.1"); l3.add("test
3.2"); l3.add("test
3.3"); l2.add(l3); l2.add("test
2.4"); l2.add("test
2.5"); l2.add("test
2.6"); l3
= new ArrayList(); l3.add("test
3.1"); l3.add("test
3.2"); l3.add("test
3.3"); l2.add(l3); l1.add(l2); l2
= new ArrayList(); l2.add("test
2.1"); l2.add("test
2.2"); l2.add("test
2.3"); l1.add(l2); l1.add("test
1.3"); l1.add("test
1.4"); l1.add("test
1.5"); return
convertToTreeModel(l1); } private
TreeModel convertToTreeModel(List list) { TreeModel
model = null; DefaultMutableTreeNode
rootNode = new DefaultMutableTreeNode(new ModelBean("ROOT")); add(rootNode,
list); model
= new DefaultTreeModel(rootNode); return
model; } private
void add(DefaultMutableTreeNode parent, List sub) { for
(Iterator i = sub.iterator(); i.hasNext();) { Object
o = i.next(); if
(o instanceof List) { DefaultMutableTreeNode
child = new DefaultMutableTreeNode(new ModelBean("subtree...")); parent.add(child); add(child,
(List)o); } else { DefaultMutableTreeNode
child = new DefaultMutableTreeNode(new ModelBean(o.toString())); parent.add(child); } } } /** *
@see wicket.Component#isVersioned() */ public
boolean isVersioned() { //
TODO Bug: Versioning gives problems... probably has to do with markup //
inheritance return
false; } } TreePanel.html <html> <wicket:panel> <span wicket:id="tree"></span> </wicket:panel> </html> MainPanel.java public class MainPanel extends Panel{ public MainPanel(String s, IModel
iModel) { super(s,
iModel); add(new
Label("main",iModel.toString())); } } MainPanel.html <html> <wicket:panel> <span wicket:id="main"></span> </wicket:panel> </html> |
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user