Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use OR condition in Logic Tags

 
swaroop gunta
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to use two logic:equal conditions and put your line inside both these conditions.
 
Zip Ped
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And sorry for flooding the topic with similar replies.
 
swaroop gunta
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
In such a case i will be printing the same line twice which is undesired
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Merrill and Brent
I shall check out if using those tags is allowed by the standards we follow.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic