You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Steven McClintoc <mc...@gmx.net> on 2006/01/15 00:03:19 UTC

html:link and nested java logic (2)

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.

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.

Does someone know a solution to this problem?

I'm fairly new to struts and html/css, so any help would be greatly
appreciated!



Thanks in advance,
Steven McClintoc



-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen f�r GMX Partner: http://www.gmx.net/de/go/partner

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: html:link and nested java logic (2)

Posted by Laurie Harper <la...@holoweb.net>.
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org