• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use OR condition in Logic Tags

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
In such a case i will be printing the same line twice which is undesired
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Merrill and Brent
I shall check out if using those tags is allowed by the standards we follow.
 
reply
    Bookmark Topic Watch Topic
  • New Topic