• 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

logic tags in JSTL?

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can I map my bean property to the expression language?
 
Author
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic