Hi Cedric Thanks a million, code works like a charm, my logic was a little off, you have clarified it wonderfully.
>From: Cedric Dumoulin <[EMAIL PROTECTED]> >Reply-To: [EMAIL PROTECTED] >To: [EMAIL PROTECTED] >Subject: Re: Tiles - Dynamic menu creation - logic problems >Date: Fri, 19 Oct 2001 12:14:01 +0200 > > > Hello, > > There is some mismatch in your code ;-) > > First, in your <insert>, you put several time an attribute using the >same name >(linknormal). Each addition overload previous value, so only the last value >remains. > Second, in your submenu.jsp, you iterate on both lists, but you do logic >on >external beans, not on bean resulting from iteration. > Such external beans (novalue, linkbold, linknormal) exist because you >have >imported them from tiles attribute list, and "put" them in attribute list >from ><insert>. > > Personally, I would create a third list, holding flags like bold, link, >separator, ... Such flags indicate what I would like to do with an item. > In submenu.jsp, I would iterate also on third list to check flag values, >and >do appropriate output. > I have put the proposed code at the end. I haven't check it, so some >typo >error may remain. Let us know if it works for you. > > I am currently working on a new Tiles feature that will simplify such >construct. The idea is to allow to <put> or <add> a bean. You specify bean >class, and properties values. In your case, there will be 3 properties >(item, >link, flag). For other menus, there could also have (img, tooltips, ...). >Menu.jsp will be also simplified because you will iterate on only one list. >Logic will apply on each iterated bean properties. > > > Cedric > > Proposed code for <insert> looks like : > ><%@ taglib uri="/WEB-INF/tiles.tld" prefix="comp" %> ><comp:insert page="/hfa/common/submenu.jsp" flush="true"> > ><comp:put name="title" value="submenu" /> > ><comp:putList name="items" > ><comp:add value="Create" /> ><comp:add value="Search" /> ><comp:add value="Requests:" /> ><comp:add value="Drafts" /> ><comp:add value="In Process" /> ></comp:putList> > ><comp:putList name="links" > > <comp:add value="create.jsp" /> > <comp:add value="search.jsp" /> > <comp:add value="" /> > <comp:add value="drafts.jsp" /> > <comp:add value="inprocess.jsp" /> ></comp:putList> > ><comp:putList name="flags" > > <comp:add value="linkbold" /> > <comp:add value="linknormal" /> > <comp:add value="nolink" /> > <comp:add value="linknormal" /> > <comp:add value="linknormal" /> ></comp:putList> > ></comp:insert> > >Tile submenu.jsp will be : > ><%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> ><%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> ><%@ taglib uri="/WEB-INF/tiles.tld" prefix="comp" %> ><%@ page import="java.util.Iterator" %> > ><%-- Push Tiles attributes in page context --%> ><comp:importAttribute /> > ><bean:define id="links" name="links" type="java.util.List" scope="page" /> ><bean:define id="items" name="items" type="java.util.List" scope="page" /> ><% Iterator linksIterator = links.iterator(); %> ><% Iterator itemsIterator = items.iterator(); %> > ><logic:iterate id="flag" name="flags" type="java.lang.String" >scope="page"> > ><% // Compute link value > String link = (String)linksIterator.next(); > String item = (String)itemsIterator.next(); > %> > ><logic:equal name="flag" value="nolink"> ><%=item%> ></logic:equal> > ><logic:equal name="flag" value="linkbold"> ><B><a href="<%=link%>"><%=item%></a></B> ></logic:equal> > ><logic:equal name="flag" value="linknormal"> ><a href="<%=link%>"><%=item%></a> ></logic:equal> > ></logic:iterate> > > > >iT meDic wrote: > > > Hello all , i have a problem on which i have been stuck for 3 days, i >have > > asked numerous developers and worked on this problem for days but to no > > avail, i would be extremely grateful if you could advise me on how to > > overcome this monstrous beast! > > > > I am using the struts framework components to create a componentized > > submenu. I used the struts example(tiles) to build upon the submenu >which is > > being generated dynamically using this file:- > > > > <%@ taglib uri="/WEB-INF/tiles.tld" prefix="comp" %> > > <comp:insert page="/hfa/common/submenu.jsp" flush="true"> > > > > <comp:put name="title" value="submenu" /> > > > > <comp:putList name="items" > > > <comp:add value="Create" /> > > <comp:add value="Search" /> > > <comp:add value="Requests:" /> > > <comp:add value="Drafts" /> > > <comp:add value="In Process" /> > > </comp:putList> > > > > <comp:putList name="links" > > > <comp:add value="create.jsp" /> > > <comp:add value="search.jsp" /> > > <comp:add value="nolink" /> > > <comp:add value="drafts.jsp" /> > > <comp:add value="inprocess.jsp" /> > > </comp:putList> > > > > <comp:put name="novalue" value="nolink" /> > > <comp:put name="linkbold" value="Create" /> > > <comp:put name="linknormal" value="Search" /> > > <comp:put name="linknormal" value="Drafts" /> > > <comp:put name="linknormal" value="In Process" /> > > </comp:insert> > > > > The two lists are straight forward(one item and the other links), the >issues > > i have are the following > > > > Basically i need to do three states. The first is to have a link which >is > > bold(eg. create) the second state is to have nolink(eg Requests), and >the > > third state is to have a normal link. I would like to represent all >three > > states in one page. When i execute the page, for some reason i can get >the > > process to work however, create and request are repeated as normal >links. > > So i get the desired result, create is bold, request has no link, and >drafts > > is a normal link, but create and request is repeated as normal links!!! > > I have tried 1 million and one things and it does not work, it could be > > something very simple but i do not see it. I would appreciate any help >.. > > thank you > > > > Here is the submenu.jsp file which is called upon from the page above. > > > > <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> > > <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> > > <%@ taglib uri="/WEB-INF/tiles.tld" prefix="comp" %> > > <%@ page import="java.util.Iterator" %> > > > > <%-- Push component attributes in page context --%> > > <comp:importAttribute /> > > > > <bean:define id="links" name="links" type="java.util.List" scope="page" >/> > > <% Iterator i = links.iterator(); %> > > > > <logic:iterate id="linknormal" name="items" > > > > > <bean:define id="item" name="linknormal" type="java.lang.String" > > scope="page" /> > > > > <% // Compute link value > > String link = (String)i.next(); > > %> > > > > <logic:equal name="novalue" value="<%=link%>"> > > <%=item%> > > </logic:equal> > > > > <logic:equal name="linkbold" value="<%=item%>"> > > <B><a href="<%=link%>"><%=item%></a></B> > > </logic:equal> > > > > <logic:equal name="linknormal" value="<%=item%>"> > > <a href="<%=link%>"><%=item%></a> > > </logic:equal> > > > > </logic:iterate> > > > > Also tried to do it this way:- > > > > All i did was to replace the id to iterateItems > > <logic:iterate id="iterateItems" name="items" > > > > > <bean:define id="item" name="iterateItems" type="java.lang.String" > > scope="page" /> > > > > but the problem with this approach is that it only picks up just one of >the > > logic:equal 'linknormal'(actaully the last one), eg, it would only spit >out > > In Process(and it will hide drafts and search), it won't allow me to >pass > > multiple values for the same logic:equal ... > > > > and i also have tried numerous other methods, still stuck ... will >really > > really appreciate any feedback. > > Cheers, > > > > it_medic > > > > _________________________________________________________________ > > Get your FREE download of MSN Explorer at >http://explorer.msn.com/intl.asp > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

