aspose file tools*
The moose likes Struts and the fly likes logic:equal - AND / OR? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "logic:equal - AND / OR?" Watch "logic:equal - AND / OR?" New topic
Author

logic:equal - AND / OR?

Johann Evans
Ranch Hand

Joined: Nov 18, 2002
Posts: 47
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

Joined: Nov 09, 2000
Posts: 6450
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

Joined: Nov 18, 2002
Posts: 47
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

Joined: Nov 09, 2000
Posts: 6450
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

Joined: Oct 15, 2001
Posts: 5371
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


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
I checked JSTL tutorial but could not found helpful for OR implementation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: logic:equal - AND / OR?