File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How to use OR condition in Logic Tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to use OR condition in Logic Tags" Watch "How to use OR condition in Logic Tags" New topic
Author

How to use OR condition in Logic Tags

swaroop gunta
Greenhorn

Joined: Nov 08, 2006
Posts: 3
Hi
In my jsp i use Logic tags to check conditions
To display a particular line , we check for 2 different conditions...if either is true, we display that line..

the logic conditions are like below.
<logic:equal name="<%=X%>" property="Y.a" value="1" >
<logic:equal name="<%=X%>" property="Z.a" value="1" >

can you pls suggest me how i can easily introduce an OR between them
Zip Ped
Ranch Hand

Joined: Jul 26, 2005
Posts: 336
You have to use two logic:equal conditions and put your line inside both these conditions.
Zip Ped
Ranch Hand

Joined: Jul 26, 2005
Posts: 336
You have to use two logic:equal conditions and put your line inside both these conditions. I am not aware of any other solution as the taglib doesnt provide any other solution.
Zip Ped
Ranch Hand

Joined: Jul 26, 2005
Posts: 336
You have to use two logic:equal conditions and put your line inside both these conditions. I am not aware of any other way as the taglib doesnt provide it.
Zip Ped
Ranch Hand

Joined: Jul 26, 2005
Posts: 336
And sorry for flooding the topic with similar replies.
swaroop gunta
Greenhorn

Joined: Nov 08, 2006
Posts: 3
Hi
In such a case i will be printing the same line twice which is undesired
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Nesting one condition inside the other will create an and condition, not an or condition.

One of the limitations of the <logic:xxx> tags is that there is no easy way to do an or condition. I'd advise you to use JSTL:

<c:if test="${y.a == 1 || z.a == 1}">whatever</c:if>


Merrill
Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I agree that jstl would be the preferred solution. Another solution is to add a method to your form that returns a boolean. You can then reference this property in your logic tag. Something like this:


- Brent
swaroop gunta
Greenhorn

Joined: Nov 08, 2006
Posts: 3
Thanks Merrill and Brent
I shall check out if using those tags is allowed by the standards we follow.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use OR condition in Logic Tags