File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes logic tags in JSTL? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "logic tags in JSTL?" Watch "logic tags in JSTL?" New topic
Author

logic tags in JSTL?

John Holme
Ranch Hand

Joined: Oct 11, 2002
Posts: 54
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

Joined: Mar 09, 2001
Posts: 2676
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}">


Matthew Phillips
John Holme
Ranch Hand

Joined: Oct 11, 2002
Posts: 54
how can I map my bean property to the expression language?
David Geary
Author
Ranch Hand

Joined: Apr 23, 2003
Posts: 45
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)


David Geary Sabreware, Inc<br /><a href="http://www.corejsf.com" target="_blank" rel="nofollow">http://www.corejsf.com</a><br /> <br />Author: Graphic Java Series, Advanced JavaServerPages, Core JSTL and Core JavaServer Faces
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
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.
 
 
subject: logic tags in JSTL?