views:

145

answers:

2

I would like to indicate the currently chosen page in a shared menu component of a web page in a Struts Tiles project.

I can think of some possible solutions

  • check current URL
  • call some Javascript to indicate
  • possibly hooked into the tiles or struts config files and read.

I'm sure this problem has been faced many times before. What is the best way of dealing with this?

A: 

Did you consider using struts-menu? It integrates nicely with Tiles if I remember well.

Pascal Thivent
Thanks, the site was pretty much complete accept this, so I didn't want to add or change any other components.
Pool
A: 

I used the following method:

tiles-des.xml

    <definition name=".basic.layout" path="/WEB-INF/jsps/basicLayout.jsp">
        <put name="title" value=""/>
        <put name="homeMenuClass" value=""/>
        <put name="forumMenuClass" value=""/>
        <put name="helpMenuClass" value=""/>
    </definition>

And in the same file set the appropriate menu class to "active" for differing tiles.

basicLayout.jsp

    <li class="<tiles:getAsString name="homeMenuClass"/>">...
    <li class="<tiles:getAsString name="forumMenuClass"/>">...
    <li class="<tiles:getAsString name="helpMenuClass"/>">...
Pool