Highlight Selected Menu For Current Page Using SiteMesh

30 05 2008

In my previous post, Dynamically Load Menus with SiteMesh, I described how to load menus dynamically based on the variable in the pages. Here, to highlight last selected menu (which means current menu item) we can use same thing.

This time the variables we specify in every page will be name for the menu items.
And instead of include jsp page in the previous post, we need to set menu items like this :

<li>  
   <a class="${currentMenu == 'abc_menu' ? 'selected':''}"      
       title="Abc" href="abc.html">Abc</a>
</li>

Here, for every menu item, it is needed to specify class decision. And do not forget to add css style for selected.





Dynamically Load Menus with SiteMesh

30 05 2008

If you want to load different menus based on the current page using SiteMesh, you are on the right blog entry:)

In your template page, get decorator property and set it to currentMenu variable.

<c:set var="currentMenu" scope="request">
    <decorator:getProperty property="meta.menu"/>
</c:set>

and use it to include menu as menu page name

<jsp:include page="/includes/${currentMenu}.jsp"/>

and in your jsp pages, specfiy which menu to be used when this page is loaded

<meta name="menu" content="abc_menu"/>

Here, be careful with the names. As in the last code, you stated your menu name abc_menu. Then you need a jsp page for menu : abc_menu.jsp. You may only just menu items.

If you state in another jsp page something like this :

<meta name="menu" content="abc_menu2"/>

then you will need abc_menu2.jsp

That is it.








Follow

Get every new post delivered to your Inbox.