I am trying to create a nested unordered list structure similar to the one
demonstrated by the nested example from org.apache.wicket.examples. However,
there are some key differences that have me stumped.

Here is an example of the structure I am trying to create:

<html>
<body>
<ul id="menu1">
    <li>
        <a href="#">1.1</a>
    </li>
    <li>
        <a href="#">1.2 </a>
        <ul id="menu1.2">
            <li>
                <a href="#">1.2.1</a>
            </li>
            <li>
                <a href="#"> 1.2.2</a>
            </li>
            <ul id="menu1.2.2">
                <li>
                    <a href="#">1.2.2.1</a>
                </li>
            </ul>
            <li>
                <a href="#">1.2.3</a>
            </li>
        </ul>
    </li>
    <li>
        <a href="#">1.3</a>
    </li>
</ul>
</body>
</html>

The code I have attached comes close to replicating this structure but has
one key difference that is throwing off the css/javascript combination
required to style this block for IE. In the code attached, each <li> tag is
wrapped in a <span wicket:id="rows"> tag. From what I can tell, this element
is required by the org.apache.wicket.markup.html.list.ListView class I am
using to recursively build the nested list.

I have tried using a ListView (attached), a RepeatingView, plus several html
template structures but I haven't come upon a solution that eliminates the
<span> elements. I could try to tweak the style sheet or the script but I'm
the kind of person who is more comfortable working in Java. Plus, I know
wicket can do it and it burns me that I can't figure it out.

Anyone have any ideas?

Thanks,

Jay


NavigationPanel.java:

public class NavigationPanel extends Panel {
    private static final long serialVersionUID = 1013065866921645502L;

    /**
     * Constructor
     * @param id         - Wicket ID
     * @param menus     - List of NavMenuItems
     * @param parentID     - HTML ID of parent (or null if root menu)
     */
    public NavigationPanel(String id, List<NavMenuItem> menus, String
parentID) {
        super(id);
        AttributeModifier idModifier = null;
        if (parentID == null) {
            idModifier = new AttributeModifier("id",new Model("nav"));
            add(HeaderContributor.forCss(NavigationPanel.class, "
NavigationPanel.css"));
            add(HeaderContributor.forJavaScript(NavigationPanel.class, "
NavigationPanel.js"));
        } else
            idModifier = new AttributeModifier("id",new Model(parentID));
        add(new MenuPanel("menu", menus).add(idModifier));
    }

    private class MenuPanel extends Panel {
        private static final long serialVersionUID = -595725676357588882L;

        MenuPanel(String id, List<NavMenuItem> menus) {
            super(id);
            add(new Rows("rows", menus));
            setVersioned(false);
        }

        /**
         * The list class.
         */
        private class Rows extends ListView {
            private static final long serialVersionUID =
-5175513182419457939L;

            /**
             * Constructor
             * @param name - name of the component
             * @param list - a list where each element is either a string or
another list
             */
            public Rows(String name, List<NavMenuItem> list) {
                super(name, list);
            }

            /**
             * @see org.apache.wicket.markup.html.list.ListView#populateItem
(org.apache.wicket.markup.html.list.ListItem)
             */
            protected void populateItem(ListItem listItem) {
                NavMenuItem navMenuItem =
(NavMenuItem)listItem.getModelObject();

                WebMarkupContainer row = new WebMarkupContainer("menuItem");
                String linkText = navMenuItem.getMenuText();

                NavigationPanel nested = new NavigationPanel (
                        "subMenu",
                        navMenuItem.getSubMenus(),
                        navMenuItem.getMenuText()
                        );
                if (navMenuItem.getSubMenus() == null)
                    nested.setVisible(false);
                else
                    linkText = linkText + " &#187;";

                Label link = new Label("link", linkText);

                row.add(nested);
                row.add(link);
                listItem.add(row);
            }
        }
    }
}



NavigationPanel.html:

<html xmlns:wicket>
<wicket:panel>
<ul wicket:id="menu" id="">
    Navigation menu goes here
</ul>
</wicket:panel>
</html>



NavigationPanel$MenuPanel.html:

<html xmlns:wicket>
<wicket:panel>
<span wicket:id="rows">
<li wicket:id="menuItem"><a href="#" wicket:id="link">Link Text</a><span
wicket:id="subMenu"/></li>
</span>
</wicket:panel>
</html>

Reply via email to