Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OR condition implementation using logic:equal

 
Mathur Neni
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • 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.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you'll have to use jstl core or plain ol' scriptlets.
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Jim Steinberger
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic