Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL doubts (c:if)

 
Rafael Afonso
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello:
I have a JSP Page with following code:

To not mix Java code with HTML, I am beginning to use the JSLT from the Jakarta Project. My page was thus:

Now the code does not function as before. The content inside of tag c:if does not appear no way. I tried to make test="${!empty stringSearch}" but the same thing happened. How I must "translate" the condition of the original code for tag?
Thanks,
[ February 19, 2003: Message edited by: Rafael Afonso ]
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem #1 is that, while you change the local reference variable "stringSearch", you don't actually change the page-scoped attribute of the same name (as in JspContext.setAttribute(.., PAGE_SCOPE)). Hence the JSTL cannot see your change and will see an empty String.
Problem number two is probably that the JSTL EL does not have an operator "&&". Replace it by "and". The up-and-coming JSP 2.0 will support "&&", though; a boon for Java geeks
In any case, this is not very idiomatic; I would suggest you replace the code by something likeIf you really want the stringSearch variable, useBy the way, in JSP 2.0 you'd simply sayHTH
- Peter
[ February 19, 2003: Message edited by: Peter den Haan ]
 
Rafael Afonso
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter:
It works! Thanks for lesson. What means HTH?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope This Helps
- Peter
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a quick clarification - JSTL 1.0 supports the 'empty' keyword, so you don't have to wait for JSP 2.0 to use it.
JSP 2.0's major new feature is that it lets you use the EL anywhere -- in template text, custom tags, and so forth.
"HTH"
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shawn Bayern:
Just a quick clarification - JSTL 1.0 supports the 'empty' keyword, so you don't have to wait for JSP 2.0 to use it.
D'oh. That's what you get for using the public draft of the JSTL spec instead of the final thing
- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic