Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

logic tags in JSTL?

 
John Holme
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can JSTL or built-in jsp tags be used to implement functionality similar to the Struts logic tags? Here's what I want to do...
I've set a bean as a request attribute (called "featureBean"), which I'm accessing in my jsp via the jsp:useBean tag. I want to make a chunk of html dependent on the value of a boolean field of "featureBean".
I can't do this using a jsp:getProperty tag, because it's not a body tag. I could use an expression like featureBean.getBoolean() in a scriptlet; but I'm trying to avoid jsp scriptlets.
Can I do this using built-in jsp tag functionality or a jsp expression? Can I do it using JSTL?
Thanks for your thoughts!
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The if tag of JSTL has a test parameter. You can use JSTL's expression language in that parameter to access the properties of your bean like so:
<c:if test="${bool.isTrue}">
 
John Holme
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can I map my bean property to the expression language?
 
David Geary
Author
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Holme:
Can JSTL or built-in jsp tags be used to implement functionality similar to the Struts logic tags? Here's what I want to do...
I've set a bean as a request attribute (called "featureBean"), which I'm accessing in my jsp via the jsp:useBean tag. I want to make a chunk of html dependent on the value of a boolean field of "featureBean".
I can't do this using a jsp:getProperty tag, because it's not a body tag. I could use an expression like featureBean.getBoolean() in a scriptlet; but I'm trying to avoid jsp scriptlets.
Can I do this using built-in jsp tag functionality or a jsp expression? Can I do it using JSTL?
Thanks for your thoughts!

Sure:
<c:if test='${featureBean.value}'>
optional html goes here
</c:if>
(assuming your boolean variable is named value and not boolean)
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Holme:
how can I map my bean property to the expression language?

They are stored in either the page, request, session, or application scope.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic