File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

logic:equal - AND / OR?

 
Johann Evans
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to do a OR with this tag e.g.
<logic:equal name="titleForm" property="action" scope="request" value="Edit||Create">
TIA
 
Jason Menard
Sheriff
Posts: 6450
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. The value attribute is a constant. If the value can be converted to a double or a long, numeric comparison will be performed, otherwise String comparison will be performed.
Struts Logig Tags
 
Johann Evans
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx!
What is the common workaround / solution if one should like to evaluate for two or more values like in my problem scenario?
 
Jason Menard
Sheriff
Posts: 6450
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Johann Evans:
Thx!
What is the common workaround / solution if one should like to evaluate for two or more values like in my problem scenario?

There are a couple of ways you can do this. It can get kind of cumbersome but here are some options:
1) AND - use nested logic:equals tags. Place the code you want to execute inside the innermost logic:equal tag. It will only execute if both conditions are true.
2a) OR - check the condition twice. Obviously this isn't an optimal solution but will do in a pinch.
2b) OR - evaluate the condition and set a variable based on the outcome (for example "true" if the OR condition is true, "false" if it is false). Evaluate that variable with your logic:equals tag.
3) Use the JSTL. I'm not too familiar with it, but I believe they have a more robust set of conditional tags. The Struts gurus are even recommending you use JSTL tags when appropriate, so you don't have to feel like you're doing something taboo by going this route.
HTH
 
R K Singh
Ranch Hand
Posts: 5382
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jason Menard:

2a) OR - check the condition twice. Obviously this isn't an optimal solution but will do in a pinch.
2b) OR - evaluate the condition and set a variable based on the outcome (for example "true" if the OR condition is true, "false" if it is false). Evaluate that variable with your logic:equals tag.
HTH

Still I am not very clear how to implement OR in struts ??
any small example would help, let us say
if(i > 4 || j < 10) {
// do something
}
How to implement this in struts with logic tags ??
TIA
 
R K Singh
Ranch Hand
Posts: 5382
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked JSTL tutorial but could not found helpful for OR implementation.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic