File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

if statement with stuts:logic

 
Peter Primrose
Ranch Hand
Posts: 755
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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")'>
</logic:equal>

thanks in advance
 
Vani Bandargal
Ranch Hand
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest to use JSTL tags
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
</logic:greaterThan>

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}>
Excellent!
</c:when><ctherwise>
Poor
</ctherwise></c:choose>
[ October 18, 2006: Message edited by: Merrill Higginson ]
 
Peter Primrose
Ranch Hand
Posts: 755
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
thanks
 
kapil patel
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 755
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
session.getAttribute("grade")

but still get the same 'excellent' message either way
 
Peter Primrose
Ranch Hand
Posts: 755
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 755
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, I changed it to struts-logic and it works.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic