I have a LinkTree with BookmarkablePageLinks, wherein the nodes correspond to different types of objects. The models within the nodes tell me what kind of page I need to instantiate, with what parameters. I had some troubles implementing it, but I got it working. Since this kind of pattern is common within UIs and I have been helped on other occasions by people here, I'm posting what I figured out in order to give back to the community.
public class MyLinkTree extends LinkTree { public MyLinkTree(String id, TreeModel model) { super(id, model); setLinkType( org.apache.wicket.markup.html.tree.BaseTree.LinkType.REGULAR ); } @Override protected Component newNodeComponent( String id, IModel model ) { return new LinkIconPanel( id, model, MyLinkTree.this ) { private static final long serialVersionUID = 1L; @Override protected void addComponents( final IModel model, final BaseTree tree ) { final Object obj = ( ( DefaultMutableTreeNode )model.getObject() ).getUserObject(); BaseTree.ILinkCallback callback = new BaseTree.ILinkCallback() { private static final long serialVersionUID = 1L; public void onClick( AjaxRequestTarget target ) { PageParameters params = new PageParameters(); if ( obj instanceof BeanA ) { target.appendJavascript("window.location="+MyLinkTree.this.urlFor( PageA.class, params ) ); } else if ( obj instanceof BeanB ) { params.add( "myParamKey", "myParamVal" ); target.appendJavascript("window.location="+MyLinkTree.this.urlFor( PageB.class, params ) ); } } }; MarkupContainer iconContainer = tree.newLink( "iconLink", callback ); iconContainer.add(newImageComponent("icon", tree, model)); add( iconContainer ); PageParameters params = new PageParameters(); if ( obj instanceof BeanA ) { final BeanA myBean = ( BeanA )obj; BookmarkablePageLink contentLink = new BookmarkablePageLink( "contentLink", PageA.class, params ); contentLink.add( new Label( "content", myBean.toString() ) ); add( contentLink ); } else if ( obj instanceof BeanB ) { final BeanB myBean = ( BeanB )obj; params.add( "myParamKey", "myParamVal" ); BookmarkablePageLink contentLink = new BookmarkablePageLink( "contentLink", PageB.class, params ); add( contentLink ); } } }; } } -- View this message in context: http://www.nabble.com/LinkTree-with-BookmarkablePageLinks-tp21962723p21962723.html Sent from the Wicket - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org