• 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

OR condition implementation using logic:equal

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to write a OR condition like the following, using <logic:equal>

if (param1 == 1 || param2==1) {
// do this
}

Please clarify.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you'll have to use jstl core or plain ol' scriptlets.
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is how I tackled this one, please let me know if it works for you. I would have like to avoid using the scriptlet, but it was the only solution I could think of.

 
Mathur Neni
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think at some places, we need to live with, by having combination of struts tags and scriplets/jstl for some functionality.

Now got solved.

Thanks Marc and Kim.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know you got a solution working -- wanted to put my two cents in for other people that happen by.

--------------
if (param1 == 1 || param2==1) {
// do this
}
--------------

FYI, if for some reason you're dead-set against using jstl core or scriptlets, you *can* achieve OR-logic with logic:equal tags:

<logic:equal name="param1" value="1">
<!-- do this -->
</logic:equal>
<logic:equal name="param2" value="1">
<!-- do this -->
</logic:equal>

Yes, "<!-- do this -->" will be repeated HTML, but it's up to us to weigh the tradeoffs. Certainly, with the massive hard drives in today's servers, JSPs don't have to be as tiny as possible. Also, as long as the values you're comparing aren't calculated -- or, even worse, being queried via a connection to a remote database -- extra comparisons aren't going to substantially affect processing time.

One issue is maintenance, but if you extract "<!-- do this -->" into a template file to be jsp:included, that issue goes away.


Of course, a better solution is to have a JavaBean that returns "(param1 == 1 || param2==1)" as a boolean, so you can merely:
<logic:equal name="bean" property="orCondition" value="true">
<!-- do this -->
</logic:equal>

That way, non-trivial (business?) logic is out of the JSP.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic