You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Raible, Matt" <Ma...@cable.comcast.com> on 2003/05/14 23:46:08 UTC

RE: Creating root menu layout in Tiles

How about defining the displayer in a variable of some sort/scope - maybe on
application startup or something.

For instance.

getServletContext().setAttribute("displayer", "ListMenu");

and then in all your menu*.jsp pages, use:

<menu:useMenuDisplayer
name='<%=(String)application.getAttribute("displayer")%>' .../>

If you have an idea of how struts-menu could make this easier for you - let
me know - or enter it as an enhancement request on the struts-menu site
(http://sf.net/projects/struts-menu).

HTH,

Matt


-----Original Message-----
From: C H [mailto:gazellleee@hotmail.com]
Sent: Wednesday, May 14, 2003 3:38 PM
To: struts-user@jakarta.apache.org
Subject: Creating root menu layout in Tiles 


Hi,

I was wondering if anyone can help me figure out how I can define an 
inheritance
structure in Tiles for my menus (which uses Struts-Menu) so that if I want 
to change
the displayer type, I can do this in just one spot.

The site I'm working on has a number of tabs (ex. Home, Reports, Admin).  My
base tile layout has a header, top menu (i.e. tabs), side menu, body and 
footer.
For each tab, I display a different menu.  For the menu tile, I'm currently
using the ListMenu displayer. If possible, I'd like to define a menu 
hierarchy
using tiles so that if I decide to change the displayer in the future (say 
to
CoolMenu4), I can do this in just one place (ideally the root Menu layout).

My basic menu tile looks something like the following.  For each tab, the 
only
thing that differs in the menu tile is the displayMenu name.

------------- MENU.JSP -----------
<HEAD>
<%@ taglib uri="/WEB-INF/struts-menu.tld" prefix="menu"%>
<link rel="stylesheet" type="text/css" media="screen"
            href="<%=request.getContextPath()%>/styles/menuExpandable.css" 
/>
</HEAD>
<BODY >
<!-- Side menu begin -->
<script type="text/javascript"
src="<%=request.getContextPath()%>/scripts/menuExpandable.js"></script>
<menu:useMenuDisplayer name="ListMenu"
        bundle="org.apache.struts.action.MESSAGE"
		   permissions="myOwnAdapter">
        <menu:displayMenu name="MenuHome"/>   //<- ONLY THIS MENU NAME
</menu:useMenuDisplayer>                                //CHANGES FOR EACH 
TAB
<!-- Side menu end -->
</BODY>
----------------------------------------------

In the hopes of creating a menu hierarchy whereby each tab menu inherits 
from
the base and changes only the displayMenu name, I defined the following 
Tiles:

------------- TILES DEFINITIONS -------------

<definition name="root.menu.layout" path="/layouts/menuRootLayout.jsp">
	<put name="menuName" value="" />
</definition>

<definition name="menu.home" extends="root.menu.layout">
	<put name="menuName" value="/menu/homeMenuName.jsp" />
</definition>

<definition name="menu.reports" extends="root.menu.layout">
	<put name="menuName" value="/menu/reportsMenuName.jsp" />
</definition>
--------------------------------------------------------


----------- menuRootLayout.jsp looks like --------------

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/struts-menu.tld" prefix="menu"%>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

bundle="org.apache.struts.action.MESSAGE" permissions="myOwnAdapter">

------------------------------------------------------------

I tried the following but none of these worked:

1) created a jsp file called homeMenuName.jsp containing
<menu:displayMenu name="MenuHome"/> and set
<put name="menuName" value="/menu/homeMenuName.jsp" /> in menu.home

2) instead of writing <tiles:insert attribute="menuName"/> in
menuRootLayout.jsp, wrote this as
<tiles:getAsString name="menuName"/>
then in the tile definition of ="menu.home", changed the put tag to
<put name="menuName" value="&lt; menu:displayMenu name='homeMenu'/ &gt;" />

The only thing that worked was when I passed the whole 
<menu:useMenuDisplayer>
block as a parameter of the main root tile (and modified menuRootLayout.jsp 
to
insert this), which wasn't ideal since I'll still have to change all my menu
jsp's if I decide to change the type of displayer.

Can anyone suggest a way to make it work so that if I decide to change the
displayer type in the future, I make the change in one spot only?

Sorry for the long message. Would appreciate any suggestions.

Thanks,

Lisa

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.  
http://join.msn.com/?page=features/featuredemail


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org