Here's a solution I thought of for the time being; if anyone else has any better way of accomplishing this, or comments, please share them with me.
The following takes a putList containing items, as well as nested putLists (maximum one level of nesting for this example, but it can be extended to handle more): [The first item in the nested putList will be displayed in the top level menu, all subsequent items will be in the submenu] <ul> <c:catch> <c:forEach var="item" items="${menuItems}"> <!-- Top level menu item --> <c:catch var="e1"> <c:if test=" ${empty item.value}"> <!-- DUMMY TEST TO BREAK TO SUBMENU --> </c:if> <li> <a href="<c:out value="${item.link}"/>"> <c:out value="${item.value}"/> </a> </li> </c:catch> <c:if test="${not empty e1}"> <% //Get the subMenu to populate the menu with ArrayList<SimpleMenuItem> subMenu = (ArrayList<SimpleMenuItem>) pageContext.getAttribute("item"); pageContext.setAttribute("subMenu", subMenu); //Set an initial variable which will be a //placeholder telling us if the first item //hsa been added to the submenu - this item //will appear on the main menu pageContext.setAttribute("initial", true); %> <c:forEach var="subItem" items="${subMenu}"> <c:if test="${not initial}"> <c:if test=" ${empty subItem.value}"/> <!-- Submenu item --> <li> <a href="<c:out value="${subItem.link}"/>"> <c:out value="${subItem.value}"/> </a> </li> </c:if> <c:if test="${initial}"> <li> <a href="<c:out value="${subItem.link}"/>"> <c:out value="${subItem.value}"/> </a> <ul> <% //Reset initial to false pageContext.setAttribute("initial", false); %> </c:if> </c:forEach> </li> </ul> </c:if> </c:forEach> </c:catch> </ul> And, the tiles definition is as it was previously, except "somesublink" ends up being the main menu (top level) link, not a sub-menu link. Again, if anybody wishes to share their thoughts, please do... I am sure there is a better solution to this nested menu tiles issue. Thanks On 11/9/06, Elie Ciment <[EMAIL PROTECTED]> wrote:
Hi, I have an issue with Struts Tiles putList items. I can get all the items in my jsp page fine, with the links and values for each menu item. The problem is, when I try to nest a putList tag within another one, to attempt to create subMenu functionality. I have no way of retrieving the submenu items on my jsp page. For example, I have a tile definition called ".mainMenu", which defines a putList tag with 3 items. The first two are plain <item link=" http://www.google.com" value="Google Home Page"/> type of items - the third is not an item, but rather another putList: <definition name=".mainMenu" path="/WEB-INF/template/header.jsp"> <putList name="menuItems"> <item link=" http://www.google.com" value="Google Home Page"/> <item link="http://www.gmail.com" value="Google Email Page"/> <putList name="subMenu"> <item link="http://somesublink.menu/" value="SubLinkTest"/> <item link="http://somesublink2.menu/" value="SubLinkTest2"/> </putList> </definition> The point of doing this is obvious - I want to get the subMenu functionality from the tiles menu items putList tag. However, when displaying it on the jsp page, I don't know how to iterate over the submenu: For the main menu: <tiles:importAttribute name="menuItems" ignore="true"/> <!-- Menu begin --> <ul > <c:forEach var="item" items="${menuItems}"> <li><a href="<c:out value="${item.link}"/>"><c:out value="${item.value}"/></a></li> </c:forEach> </ul> That works fine for those menuitems in the "top-level" menuItems putList. When it comes to the other subMenu, I will get errors. Obviously so. The problem is that when I try to iterate over them with either c:forEach or using Struts logic:iterate tags I can't do it and get errors as well. What is interesting is that when I just output the "item" itself, I can see the entire collection of submenu items - for example: <c:out value="${item}"/> (without any ".value" or ".link") - so I know it is there and is accesible. The question is, how do I access this putList in the jsp page? Thanks for your help!!! -EC