aspose file tools*
The moose likes Struts and the fly likes OR condition implementation using logic:equal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "OR condition implementation using logic:equal" Watch "OR condition implementation using logic:equal" New topic
Author

OR condition implementation using logic:equal

Mathur Neni
Ranch Hand

Joined: May 10, 2004
Posts: 33
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

Joined: Feb 05, 2003
Posts: 4727

I think you'll have to use jstl core or plain ol' scriptlets.


A good workman is known by his tools.
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
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

Joined: May 10, 2004
Posts: 33
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

Joined: Jun 22, 2004
Posts: 3
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OR condition implementation using logic:equal