You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sriram Nookala <sr...@mediaone.net> on 2002/02/07 17:03:54 UTC
error implementing menus using tiles
I'm trying to create a dynamic menu using the tiles tutorial, but I get the
following error when I display the jsp:
[ServletException in:/topnavbar.jsp] Cannot find bean links in scope page'
What am I doing wrong?
thanks,
sriram
My implementation is as follows:
1. I have a topnvabar.jsp which is similar to the tiles example submenu.jsp:
<%@ 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 />
<table>
<logic:present name="title">
<tr>
<th colspan=2>
<div align="left"><strong><bean:write name="title"/></strong></div>
</th>
</tr>
</logic:present>
<%-- Check if selected exist. --%>
<logic:notPresent name="selected" >
<% pageContext.setAttribute( "selected", "" ); %>
</logic:notPresent>
<%-- Prepare the links list to be iterated --%>
<bean:define id="links" name="links" type="java.util.List" scope="page" />
<% Iterator i = links.iterator(); %>
<%-- iterate on items list --%>
<%-- Normally, we should write something like this :
<logic:iterate id="item" name="items" type="java.lang.String" >
But, Struts doesn't declare the TEI class for iterate, and
some web container deal badly with the declared variable.
So, we use what follow instead.
--%>
<logic:iterate id="iterateItem" name="items" >
<bean:define id="item" name="iterateItem" type="java.lang.String"
scope="page" />
<tr>
<td width="10" valign="top" ></td>
<td valign="top" >
<%-- check if selected --%>
<logic:notEqual name="selected" value="<%=item%>">
<% // Compute link value
String link = (String)i.next();
if(link.startsWith("/") )
link = request.getContextPath() + link;
%>
<font size="-1"><a href="<%=link%>"><%=item%></a></font>
</logic:notEqual>
<logic:equal name="selected" value="<%=item%>">
<font size="-1" color="fuchsia"><%=item%></font>
</logic:equal>
</td>
</tr>
</logic:iterate>
</table>
2. I have a tilesDefinitons.xml with the following relevant entries:
<tiles-definitions>
<definition name="baseDef" path="/TopLevelTemplate.jsp">
<put name="title" value="" />
<put name="topnavbar" value="topnavbar.links" />
<put name="sectionnavbar" value="/sectionnavbar.jsp" />
<put name="leftnavbar" value="/leftnavbar.jsp" />
<put name="content" value="" />
<put name="footer" value="/footer.jsp" />
</definition>
<definition name="topnavbar.links" path="/topnavbar.jsp" >
<put name="selected" value="Home" />
<putList name="items" >
<add value="Home" />
<add value="Campaign" />
<add value="Segment" />
<add value="Analyze" />
<add value="Profile" />
<add value="Admin" />
</putList>
<putList name="links" >
<add value="home.action" />
<add value="campaignlist.action?name=home" />
<add value="home.action" />
<add value="home.action" />
<add value="home.action" />
<add value="home.action" />
</putList>
</definition>
<definition name="home" extends="baseDef">
<put name="title" value="Campaign Manager Home" />
<put name="content" value="/HomeContent.jsp" />
</definition>
</tiles-definitions>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: error implementing menus using tiles
Posted by Cedric Dumoulin <ce...@lifl.fr>.
Hello,
Checking quickly your code, I can't find any problems.
Can you confirm that you have successfully installed and use Tiles
documentation ? Also, what url do you use to access the topnavbar.jsp, or its
parents ?
Cedric
Sriram Nookala wrote:
> I'm trying to create a dynamic menu using the tiles tutorial, but I get the
> following error when I display the jsp:
>
> [ServletException in:/topnavbar.jsp] Cannot find bean links in scope page'
>
> What am I doing wrong?
>
> thanks,
> sriram
>
> My implementation is as follows:
>
> 1. I have a topnvabar.jsp which is similar to the tiles example submenu.jsp:
>
> <%@ 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 />
>
> <table>
>
> <logic:present name="title">
>
> <tr>
>
> <th colspan=2>
>
> <div align="left"><strong><bean:write name="title"/></strong></div>
>
> </th>
>
> </tr>
>
> </logic:present>
>
> <%-- Check if selected exist. --%>
>
> <logic:notPresent name="selected" >
>
> <% pageContext.setAttribute( "selected", "" ); %>
>
> </logic:notPresent>
>
> <%-- Prepare the links list to be iterated --%>
>
> <bean:define id="links" name="links" type="java.util.List" scope="page" />
>
> <% Iterator i = links.iterator(); %>
>
> <%-- iterate on items list --%>
>
> <%-- Normally, we should write something like this :
>
> <logic:iterate id="item" name="items" type="java.lang.String" >
>
> But, Struts doesn't declare the TEI class for iterate, and
>
> some web container deal badly with the declared variable.
>
> So, we use what follow instead.
>
> --%>
>
> <logic:iterate id="iterateItem" name="items" >
>
> <bean:define id="item" name="iterateItem" type="java.lang.String"
> scope="page" />
>
> <tr>
>
> <td width="10" valign="top" ></td>
>
> <td valign="top" >
>
> <%-- check if selected --%>
>
> <logic:notEqual name="selected" value="<%=item%>">
>
> <% // Compute link value
>
> String link = (String)i.next();
>
> if(link.startsWith("/") )
>
> link = request.getContextPath() + link;
>
> %>
>
> <font size="-1"><a href="<%=link%>"><%=item%></a></font>
>
> </logic:notEqual>
>
> <logic:equal name="selected" value="<%=item%>">
>
> <font size="-1" color="fuchsia"><%=item%></font>
>
> </logic:equal>
>
> </td>
>
> </tr>
>
> </logic:iterate>
>
> </table>
>
> 2. I have a tilesDefinitons.xml with the following relevant entries:
>
> <tiles-definitions>
> <definition name="baseDef" path="/TopLevelTemplate.jsp">
> <put name="title" value="" />
> <put name="topnavbar" value="topnavbar.links" />
> <put name="sectionnavbar" value="/sectionnavbar.jsp" />
> <put name="leftnavbar" value="/leftnavbar.jsp" />
> <put name="content" value="" />
> <put name="footer" value="/footer.jsp" />
> </definition>
>
> <definition name="topnavbar.links" path="/topnavbar.jsp" >
> <put name="selected" value="Home" />
> <putList name="items" >
> <add value="Home" />
> <add value="Campaign" />
> <add value="Segment" />
> <add value="Analyze" />
> <add value="Profile" />
> <add value="Admin" />
> </putList>
> <putList name="links" >
> <add value="home.action" />
> <add value="campaignlist.action?name=home" />
> <add value="home.action" />
> <add value="home.action" />
> <add value="home.action" />
> <add value="home.action" />
> </putList>
> </definition>
>
> <definition name="home" extends="baseDef">
> <put name="title" value="Campaign Manager Home" />
> <put name="content" value="/HomeContent.jsp" />
> </definition>
>
> </tiles-definitions>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>