Steven McClintoc wrote:
Hi there!

I have a page which consists out of three files:
 - header.jsp
 - sidebar.jsp
 - main.jsp


header.jsp contains a navigational bar in which I want to highlight the
page currently be shown, e.g.

   -------------------------------------------------
   Home | Item1 | Item2 | *Item3*| Item4
   -------------------------------------------------

if Item3 is the active page.

Now, my first approach was to include header.jsp and sidebar.jsp with


                <jsp:include page="../includes/Header.jsp" >
                        <jsp:param name="highlight" value="home" />
                </jsp:include>

                <%@ include file="../includes/Sidebar.jsp" %>



Within Header.jsp I checked against the request parameter highlight:


                <% String hl = request.getParameter("highlight"); %>
                <a  <% if (hl.equals("guestbook")) { %> class="highlight" <%
} %> href="/Phoenix/jsp/guestbook.jsp">Guestbook</a> |



The problem is that this approach understandably doesn't work well with
URL-rewriting.

I'm not sure what the problem is with URL rewriting; what effect does that have on this approach?

Unfortunately changing the code to use <html:link> instead of <a href>
as in


                <html:link forward="guestbook"> <% if
                (hl.equals("guestbook")) { %> class="highlight" <% } %>
Guestbook </html:link> |

doesn't work. I suppose that nested tags arren't allowed here.

The problem with that is you're putting the class attribute inside the html:link element's body -- i.e. that isn't including an attribute in the generated HTML tag.

Does someone know a solution to this problem?

You might want to look into using Tiles for this sort of page composition task. It can make things a lot cleaner. But to stick with what you have, based on a request parameter to determine which link should be highlighted, here are a couple of options:

  <% String h1 = request.getParameter("highlight"); %>
  <html:link forward="guestbook" class='
      <%= h1.equals("guestbook") ? "highlight" : "" %>'>
    Guestbook
  </html:link>

or, using JSTL to avoid the ugly scriptlets:

  <html:link forward="guestbook" class="${
      param['highlight'] == 'guestbook' ? 'highlight' : ''}">
    Guestbook
  </html:link>

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to