wood burning stoves 2.0*
The moose likes Struts and the fly likes if statement with stuts:logic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "if statement with stuts:logic" Watch "if statement with stuts:logic" New topic

if statement with stuts:logic

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
I would like to perform an if statment. I have a value in my request.getAttribute("myValue").

simply put, if myValue>9 show "excelent" else "poor"

I tried using the struts:logic's tag but I'm not sure what goes to name and property (what's the diff if i may ask)

<logic:equal name='name' property='property' value='request.getAttribute("myValue")'>

thanks in advance
Vani Bandargal
Ranch Hand

Joined: Oct 06, 2005
Posts: 82
I suggest to use JSTL tags
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If, as in your example, the value you want to compare is a simple String, use only the name attribute. If it is a property of a bean, use the name attribute for the bean name, and the property attribute for the bean property.

So, in your example the tag would look like this:

<logic:greaterThan name="myValue" scope="request" value="9">
// do whatever

Let me say, though, that I agree with Vani: JSTL is a better choice for this situation as the tags are more intuitive and more powerful. Example:

<c:choose><c:when test=${myValue > 9}>
[ October 18, 2006: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
I tried this:

I get same message in both cases - when myValue is 100 or 50

I believe it has somthing to do with the myValue (I changed the name to somthing bogus and got the same message)

should I advise to a bean about that?
<jsp:useBean> somthing like that?
kapil patel
Ranch Hand

Joined: Sep 30, 2005
Posts: 33
Is your myValue in request scope?

Moreover, can you put exact code and answer you are getting?
I would recommend to refer www.apache.struts.org to get better idea of tags and it's property
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
actually it's in session scope but i changed the scope in the jsp code as well:

I can see the value on the screen when i do this:

but still get the same 'excellent' message either way
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
well i forgot the:
<%@ taglib uri="/WEB-INF/struts-logic-el.tld" prefix="logic" %>

but even with this i get en err msg:

No tag "greaterThan" defined in tag library imported with prefix "logic"'
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
ok, I changed it to struts-logic and it works.
I agree. Here's the link: http://aspose.com/file-tools
subject: if statement with stuts:logic
Similar Threads
Help needed for Struts' logic:equal
using logic:equal tag
Logic:iterate + OR condition
How to replace a if(boolean) script with struts tag?