• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

tag file question

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i wrote a test jsp using a tag file. using the input of "hi" in the jsp, i am getting "Hello world!" and "test hi!" as if when and otherwise both returned true for "hi". Any ideas?

thanks, rk

my test.jsp:

<%@ taglib prefix="mytags" tagdir="/WEB-INF/tags/label" %>

<mytags:test myname="hi" />

my test.tag:
<%@ attribute name="myname" required="true" rtexprvalue="true" %>
<c:choose>
<when test="${myname == 'hi'}">
<b>Hello world!</b>
</c:when>

<c:otherwise>
test ${myname}!
</c:otherwise>
</c:choose>
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you look at the HTML that's being returned to the browser? That's almost always the first debugging step you should take when your page isn't doing what you think it should be doing.

When you do that (via View Source) in the browser, I think that what the problem is will become clear to you.
 
Rao Kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear,

I ran the above using Tomcat 5.0 as http://localhost:8080/mytest/test.jsp
and view source shows test.jsp containing the following:

<c:choose>
<when test="true">
<b>Hello world!</b>
</c:when>

<c:otherwise>
test hi!
</c:otherwise>
</c:choose>
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly as I suspected. What is it about that that is wrong?

Should not the JSTL tags have been interpreted on the server and never been sent to the client?
 
Rao Kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a bit lost.

I read tag file is another way to do include and my jsp does show what was included. How can I make the JSTL part executed on the server?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a "normal" JSP page what would you have to do in order to allows the JSTL tags to be used? Or any custom tags for that matter?

A tag file is just a special case of a JSP page.

You need to declare the JSTL c taglib in order to use it in the tag file.
[ August 09, 2006: Message edited by: Bear Bibeault ]
 
Rao Kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,

THANKS so much for your help and prompt response!

i actually had a syntax error shown after adding the taglib reference. "<when" above needs prefixed as "<c:when" and after fixing that it worked beautifully.

rk
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah yes, I missed that. The important thing to take away, in my opinion, is that looking at the HTML source where you saw that the JSTL tags were not being evaluated was the major clue that would have told you that it wasn't an issue with how the test conditions were being evaluated, but in simply setting up the tag file correctly.
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic