Hi all. I have a groovy question for you. I'm looking for some guidance.
I have a web app with 15
jsp pages. It's
struts and uses tiles for the headers and footers. Each page has the same navigation menu on the left side, however there are some exceptions. The navigation menu has about 10 top level items. There are then two of these top level items that have subitems. The subitems are only displayed in the menu when a parent is clicked.
The menu item that corresponds to the page you are currently on, is highlighted white (the menu items are normally blue), using some css objects.
I currently have the menu hard coded in every jsp page. The appropriate menu item for each page is highlighted white in this code, and also any "trees" (parent with sub items) are displayed depending on what page we are on.
Make sense so far? Nothing too crazy going on, but I may stink at explaining it.
So, I have this yearning to put all the menu code in ONE place and not hard coded in each JSP page. Here is my plan.
Create a jsp page that is a tile, called MenuTile.jsp. This page will be called from one of the regular jsp pages using code like this:
Page1.jsp:
...
<tiles:insert page="../tiles/MenuTile.jsp" >
<tiles
ut name="pageVariable" value="page1" />
</tiles:insert>
...
In the MenuTile.jsp I will grab this attribute with this code:
<tiles:useAttribute name="pageVariable" />
I will have a whole bunch of if statements in the MenuTile.jsp. There will be an if statment for every menu item. If that menu item's name is passed in (such as "page1" here), then that menu item is changed to be white, otherwise it stays blue (this is all done in the if statment), and the menu item is then dispalyed.
It gets a little harder with the menu items that have sub items. I will need to do an initial if stmt to see if the passed in pageVariable is one of the sub items of a parent menu item. If it is, then I need to display that whole tree, otherwise I keep the whole tree hidden.
Does this sound like an appropriate plan to make a menu that is only stored in one place, and can accomodate the fact that different css code is used for a link when you are actually on that links page...and the whole menu item with sub items? Is this common practice? I'm sure people have delt with this sort of situation before. I'd love to have some help, and I'd imagine this sort of discussion might help others in the future. Thanks!