This sounds pretty cool Steve.  Doing the menu-selection on the server
side is definitely better than client side.  I've done something
similar with SiteMesh.  It'd be nice to write-up some howtos as part
of the Struts Menu documentation.  I've cc'd the Struts Menu user list
so they can see your solution.

Matt

On 1/11/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi Matt.
>
> I've done some recent work using Struts Menu - very useful, thanks.
>
> However, my project required dynamic menus without any client-side
> JavaScript for showing or selecting menu state.
>
> Since Struts Menu obviously needs to know which menu item has been
> selected, and then builds the menu on-the-fly, I thought it would be fairly
> simple to move the JavaScript logic back into the web application, and do
> it that way.
>
> I was expecting to have to extend some of the Struts Menu Java code, but it
> turned out to be a lot easier than that.
>
> The trick is to keep track of the menu state by assigning hooks to the
> selected menu items inside your Tiles definitions, loading them into the
> request inside the main Tiles layout, then pulling them back into Velocity
> to work out where you are in the menu and generate the appropriate HTML and
> CSS markup for the menu.
>
> For example, for  a 3 level menu (1 set of horizontal top buttons + 2
> further levels of nesting on a vertical side menu), you need to do
> something like:
>
> In Tiles definitions:
>
> <put name="topMenuSelected" value="topMenu_1" />
> <put name="subMenu" value="subMenu1" />
> <put name="menuSelected" value="subMenu_1_1" />
>
> In the tiles layout:
>
> <tiles:useAttribute id="topMenuSelected" name="topMenuSelected" scope=
> "request" />
> <tiles:useAttribute id="subMenu" name="subMenu" scope="request" />
> <tiles:useAttribute id="menuSelected" name="menuSelected" scope="request"
> />
>
> In the menu-config.xml:
>
> <Menu name="topMenu">
>   <Item name="topMenu_1" title="Section 1" action="/Section_1.do" />
>   <Item name="topMenu_2" title="Section 2" action="/Section_2.do" />
>
> </Menu>
>
> <Menu name="subMenu1">
>   <Item name="subMenu_1" title="S1-P1" action="/s1_page_1.do" >
>     <Item name="subMenu_1_1" title="S1-P1_1" action="/s1_page_1_1.do" />
>     <Item name="subMenu_1_2" title="S1-P1_2" action="/s1_page_1_2.do" />
>     <Item name="subMenu_1_3" title="S1-P1_3" action="/s1_page_1_3.do" />
>   </Item>
> ...
>
> Then in the Velocity, you can do:
>
> #set ($menuSelected = $request.menuSelected)
> #set ($topMenuSelected = $request.topMenuSelected)
> #set ($subMenu = $request.subMenu)
>
> ...
>
> #if($menu.name == $menuSelected)
>   #set($styleClass="selected")
>     <li class="$styleClass">$title</li>
> #else
>   #set($styleClass="unselected")
>   <li class="$styleClass"><a class="main" href="$menu.url" title="$title">
> ${title}</a></li>
> #end
>
> ...
>
> to work out where in the menu hierarchy the page that you are rendering
> should be.  It's then just a matter of writing Velocity code to generate
> your links using CSS to decorate them.
>
> You can also use exactly the same variables to build a breadcrumbs trail
> (not the click-trail type, but the "where am I in the site" type) - very
> useful.
>
> I've got a very simple working sample I can send you as a WAR file.  It's
> not huge, but I didn't want to send an email attachment without your
> agreement.  I should also have a working sample on the web very soon.
>
> Note - I decided to split the 3 tier menu into 2 separate menu chunks
> rather than deal with a single 3 level menu.  Very easy to extend to 4
> levels (2 top - 2 side).  No doubt this can be done more elegantly with
> recursion, but my time was limited and I had to bash something out very
> quickly.
>
> Finding and adapting Struts Menu without writing any new JavaCode has made
> my life much easier.
>
> If you find this idea useful, please feel free to do whatever you want with
> it.  It would be good to see it improved and incorporated into the main
> project.
>
> Anyway, thanks again for the original Struts Menu, Appfuse, and all the
> other good stuff.
>
>
>
> Steve
>
>
>
>
>
> ______________________________________________________________________
>
> ----ONLINE-SERVICES-------------------------------------------
> Find out more about our services or login at
> http://www.scottishequitable.co.uk
>
> -----EXISTING-BUSINESS-CONTACTS-------------------------------
> 08456 10 00 10 Pensions & investments ([EMAIL PROTECTED])
> 08456 10 00 52 Final salary pension schemes
> 08456 10 00 01 Online services ([EMAIL PROTECTED])
> 08456 00 14 02 Protection ([EMAIL PROTECTED])
>
> **************************************************************
> Scottish Equitable plc
> Registered Office: Edinburgh Park, Edinburgh EH12 9SE.
> Registered in Scotland (No. 144517).
> Authorised and Regulated by the Financial Services Authority.
> Telephone: 0870 242 6789
> **************************************************************
>
> ______________________________________________________________________
>
>
>                           EMAIL DISCLAIMER
>
> This message is for the intended recipient only. It may contain
> confidential or proprietary information. If you receive this message in
> error, please immediately delete it, destroy all copies of it and notify
> the sender.
> You must not use or disclose any part of this message if you are not the
> intended recipient. We may monitor all Email communication through our
> networks.
>
> If you contact us by Email, we may store your name and address to
> facilitate communication.
>
> Any views expressed in this message are those of the individual sender,
> except where the message states otherwise.
>
> We take reasonable precautions to ensure our Emails are virus free.
> However, we cannot accept responsibility for any virus transmitted by us
> and recommend that you subject any incoming Email to your own virus
> checking procedures.
>
>
>
>


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
struts-menu-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/struts-menu-user

Reply via email to