missing bean with Tiles SimpleMenu....


Web tier: servlets, JSP, Web frameworks: missing bean with Tiles SimpleMenu....

  1. missing bean with Tiles SimpleMenu.... (1 messages)

    Hoping someone will be able to point out the silly mistake…
    I’m trying to use the tiles SimpleMenu as a way of adding breadcrumbs.
    So in my tiles definition I have
    <!-- Main Layout --><br>
      <definition name=&quot;main.layout&quot; path=&quot;/mainLayout.jsp&quot;><br>
      <put name=&quot;title&quot; value=&quot;&quot;/><br>
      <put name=&quot;header&quot; value=&quot;/header.jsp&quot;/><br>
      <put name=&quot;menu&quot; value=&quot;/menu.jsp&quot;/><br>
      <put name=&quot;body&quot; value=&quot;&quot;/><br>
      <put name=&quot;footer&quot; value=&quot;/footer.jsp&quot; /> <br>
      <putList name=&quot;breadcrumbs&quot;><br>
      <item value=&quot;PRPi&quot;<br>
      classtype=&quot;org.apache.struts.tiles.beans.SimpleMenuItem&quot; /><br>
      <item value=&quot;Applications&quot;<br>
      classtype=&quot;org.apache.struts.tiles.beans.SimpleMenuItem&quot; /><br>
      <item value=&quot;Job Match Survey&quot;<br>
      classtype=&quot;org.apache.struts.tiles.beans.SimpleMenuItem&quot; /><br>
      </putList> <br>
    Then in the header.jsp page I have
    <%@ taglib uri=&quot;/WEB-INF/tlds/struts-bean.tld&quot; prefix=&quot;bean&quot;
      <%@ taglib uri=&quot;/WEB-INF/tlds/struts-html.tld&quot; prefix=&quot;html&quot;
      <%@ taglib uri=&quot;/WEB-INF/tlds/struts-logic.tld&quot; prefix=&quot;logic&quot;
      <%-- Push tiles attributes in page context --%><br>
      <tiles:importAttribute />
    <logic:iterate id=&quot;breadcrumb&quot; name=&quot;breadcrumbs&quot; type=&quot;org.apache.struts.tiles.beans.MenuItem&quot;
    <% // Add site URL if link starts with &quot;/&quot;<br>
      String link = breadcrumb.getLink();<br>
      if(link.startsWith(&quot;/&quot;) ) link = request.getContextPath() + link;<br>
      <td width=&quot;10&quot; valign=&quot;top&quot; ></td><br>
      <td valign=&quot;top&quot; ><br>
      <font size=&quot;-1&quot;><a href=&quot;<%=link%>&quot;><br>
      <logic:notPresent name=&quot;item&quot; property=&quot;icon&quot;><%=breadcrumb.getValue()%></logic:notPresent><br>
      <logic:present name=&quot;item&quot; property=&quot;icon&quot;><br>
      <% // Add site URL if link starts with &quot;/&quot;<br>
      String icon = breadcrumb.getIcon();<br>
      if(icon.startsWith(&quot;/&quot;) ) icon = request.getContextPath() + icon;<br>
    <img src='<%=request.getContextPath()%><bean:write name=&quot;breadcrumb&quot;
      property=&quot;icon&quot; scope=&quot;page&quot;/>'<br>
      alt='<bean:write name=&quot;breadcrumb&quot; property=&quot;tooltip&quot;
      scope=&quot;page&quot; ignore=&quot;true&quot;/>' /><br>
    Thing is the breadcrumbs bean is never found. Instead I get &#8220;javax.servlet.jsp.JspException:
      Cannot find bean breadcrumbs in any scope&#8221;
    I&#8217;m sure I&#8217;m missing something very obvious but I don&#8217;t know
      what it is. Anyone able to help?
  2. Fred,

    Tricky to read your post with all these escape chars kicking around. Oh for a preview function on TSS!

    I can help you a bit with this although tiles in not a thing I’m too great at.
    The major thing missing is the tiles tld so in your breadcrumb file you need to add the line
    <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

    You also need something like
    <tiles:useAttribute name="breadcrumbs" classname="java.util.List" />

    to the breadcrumb list. Your iterate then refers to the name above so the iterate tag would be
    <logic:iterate id="breadcrumb" name="breadcrumbs" type="org.apache.struts.tiles.beans.MenuItem" >

    then use breadcrumb.getValue() or whatever to build the breadcrumb list.

    I think you’ll get a problem here with context which I don’t know the answer to (basically the list isn’t in the scope of your header page). A very quick and dirty way around this would be to move the breadcrumb logic into your layout page. Does anyone else know how you push the tabList attribute into the context of the header page in this scenario?