Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

tag file question

 
Rao Kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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>

<ctherwise>
test ${myname}!
</ctherwise>
</c:choose>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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>

<ctherwise>
test hi!
</ctherwise>
</c:choose>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!