Hello Dustin,

what do you think about this? I have done it for my portal
application some time ago. It uses generics etc. by default
and creation of complex menu structures is very ease by
the reusage construct MenuPanel which you can use within
other panels :-)


/**
 * Navigation link set.
 * 
 * @author literadix.de
 */
public class MenuPanel extends Panel {

        /**
         * @param id
         * @param label 
         * @param subMenues 
         */
        public MenuPanel(String id, String label, List<LabeledLink> subMenues) {
                super(id);
                
                this.setRenderBodyOnly(true);
                
                Label topicLabel = new Label("panelLabel", label);
                topicLabel.setRenderBodyOnly(true);
                add(topicLabel);
                
                ListView listView = new ListView("list", subMenues){

                        @Override
                        protected void populateItem(ListItem listItem) {
                                final LabeledLink link = 
(LabeledLink)listItem.getModelObject();
                                Link wicketLink = link.getLink();
                                listItem.setRenderBodyOnly(true);
                                listItem.add(wicketLink);
                        }};
                        
                        listView.setRenderBodyOnly(true);               
                        
                add(listView);
        }
        
}


/**
 * @author literadix.de
 */
public class LabeledLink {

        /** Constant */
        private final static String linkObjectName = "link";
        
        /** Constant */
        private final static String labelObjectName = "label";
        
        /** Constant */
        private final static String beforeSelected = "";
        
        /** Constant */
        private final static String afterSelected = "";
        
        /**
         * Linkobject.
         */
        private final Link link;
        
        /**
         * @return BookmarkablePageLink
         */
        public Link getLink() {
                return this.link;
        }

        /**
         * @param label 
         * @param linkClass  
         */
        public LabeledLink(final String label, Class linkClass) {
                this.link = new BookmarkablePageLink(linkObjectName, linkClass);
                this.link.add(new Label(labelObjectName, label));
                this.link.setAutoEnable(true);
                this.link.setBeforeDisabledLink(beforeSelected);
                this.link.setAfterDisabledLink(afterSelected);
                
        }
        
}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";;>
<html xmlns="http://www.w3.org/1999/xhtml";; 
xmlns:wicket="http://wicket.sourceforge.net/";; xml:lang="de_DE" lang="de_DE">
        <body>
                <wicket:panel>
                        <div class="lmenutopic"><span 
wicket:id="panelLabel">some value</span></div>
                        <span wicket:id="list">
                                <a class="menu" wicket:id="link" href="#"><span 
wicket:id="label"></span></a>
                        </span>
                </wicket:panel>
        </body>
</html>


Now you can construct an overview panel and needed links like this:

                LinkedHashMap<String, LabeledLink[]> linkMap = new 
LinkedHashMap<String, LabeledLink[]>(){
                {
                        
                        put("Übersicht", new LabeledLink[]{
                                        new LabeledLink("Startseite",           
                HomePage.class),
                                        new LabeledLink("Suche",                
                SuchePage.class),
                                        new LabeledLink("Newsübersicht",        
        NewsOverviewPage.class),
                        });
                }
                ....
                add(new SubMenuList("list", subMenueList));
                ...
        private static class SubMenuList extends ListView {

                /**
                 * Constructor.
                 * @param id
                 * @param subMenueList
                 */
                public SubMenuList(String id, List<SubMenu> subMenueList) {
                        super(id, subMenueList);
                }

                /**
                 * @see 
wicket.markup.html.list.ListView#populateItem(wicket.markup.html.list.ListItem)
                 */
                @Override
                protected void populateItem(ListItem listItem) {
                        SubMenu subMenu = (SubMenu)listItem.getModelObject();
                        MenuPanel menuPanel = new MenuPanel("panel", 
subMenu.getName(), subMenu.getSubMenues());
                        
                        menuPanel.setRenderBodyOnly(true);
                        listItem.setRenderBodyOnly(true);
                        
                        listItem.add(menuPanel);
                }
                
        }

and embed it to any page this way:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";;>
<html xmlns="http://www.w3.org/1999/xhtml";; 
xmlns:wicket="http://wicket.sourceforge.net/";; xml:lang="de_DE" lang="de_DE">
        <body>
                <wicket:panel>
                        <span wicket:id="list">
                                <span wicket:id="panel"/>
                        </span>
                </wicket:panel>
        </body>
</html>

Hope this helps !

M.A.Bednarz
Hannover / Germany


> -----Ursprüngliche Nachricht-----
> Von: [email protected]
> Gesendet: 22.12.06 06:06:19
> An: [email protected]
> Betreff: [Wicket-user] Constructing a list of links from java


> 
>       I have an embarrassingly simple question to which I haven't been  
> able to find a simple answer.
> 
>       I am trying to convert an old struts and tiles/jsp app to wicket.   
> This app has a bunch of links that get added programatically.  I'd  
> like my template to have a ul to which I'd append several li elements  
> containing links.
> 
>       What is this obvious thing I'm missing?
> 
>       Thanks.
> 
> -- 
> Dustin Sallings
> 
> 
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Wicket-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
> 

-- 
mfG

Bednarz, Hannover

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to