Discussion:
using OR condition with logic tags
Sukhenko, Mikhail (Contr)
2002-10-15 21:51:32 UTC
Permalink
Hey, guys!
Do any of you know how to set up an OR condition with logic:equal tags?
i.e. :

<logic:equal name="foo" value="1"> OR <logic:equal name="foo" value="2">

Thanks
Eddie Bush
2002-10-15 22:26:56 UTC
Permalink
<logic:equal name="foo" value="1">
<!-- Stuff for when foo == 1 -->
</logic:equal>
<logic:equal name="foo" value="2">
<!-- Stuff for when foo == 2 -->
</logic:equal>

-- OR -- JSTL Approach 1

<c:choose>
<c:when test="${foo == 1}">
<!-- Stuff for when foo == 1 -->
</c:when>
<c:when test="${foo == 2}">
<!-- Stuff for when foo == 1 -->
</c:when>
</c:choose>

-- OR -- JSTL Approach 2

<c:choose>
<c:when test="${foo == 1}">
<!-- Stuff for when foo == 1 -->
</c:when>
<c:otherwise>
<!-- Stuff for when foo == 1 -->
</c:otherwise>
</c:choose>
Post by Sukhenko, Mikhail (Contr)
Hey, guys!
Do any of you know how to set up an OR condition with logic:equal tags?
<logic:equal name="foo" value="1"> OR <logic:equal name="foo" value="2">
Thanks
--
Eddie Bush
chanoch
2002-10-16 19:10:47 UTC
Permalink
however, this is quite ugly - you end up having to write two outputs for
what is basically the same problem, hence the reference to OR.

That means maintaining two Stuff's which are identical

thoughts? (except for suggesting tiles which confused my designer guys
completely - they already are trying to work out why I am "designing new
HTML elements")

chanoch


----- Original Message -----
From: "Eddie Bush" <***@swbell.net>
To: "Struts Users Mailing List" <struts-***@jakarta.apache.org>
Sent: Tuesday, October 15, 2002 11:26 PM
Subject: Re: using OR condition with logic tags
Post by Sukhenko, Mikhail (Contr)
<logic:equal name="foo" value="1">
<!-- Stuff for when foo == 1 -->
</logic:equal>
<logic:equal name="foo" value="2">
<!-- Stuff for when foo == 2 -->
</logic:equal>
-- OR -- JSTL Approach 1
<c:choose>
<c:when test="${foo == 1}">
<!-- Stuff for when foo == 1 -->
</c:when>
<c:when test="${foo == 2}">
<!-- Stuff for when foo == 1 -->
</c:when>
</c:choose>
-- OR -- JSTL Approach 2
<c:choose>
<c:when test="${foo == 1}">
<!-- Stuff for when foo == 1 -->
</c:when>
<c:otherwise>
<!-- Stuff for when foo == 1 -->
</c:otherwise>
</c:choose>
Post by Sukhenko, Mikhail (Contr)
Hey, guys!
Do any of you know how to set up an OR condition with logic:equal tags?
<logic:equal name="foo" value="1"> OR <logic:equal name="foo" value="2">
Thanks
--
Eddie Bush
--
<mailto:struts-user-***@jakarta.apache.org>
Eddie Bush
2002-10-16 20:45:09 UTC
Permalink
Oh --- OR --- I was thinking ELSE. Sorry.

JSTL solution:

<c:if test="${(foo == 1) || (foo == 2)}">
<!-- relevant code -->
</c:if>

The Struts-based solution would be the same as I mentioned before, I
believe. Sorry - I somehow understood you wanted an ELSE!
Post by chanoch
however, this is quite ugly - you end up having to write two outputs for
what is basically the same problem, hence the reference to OR.
That means maintaining two Stuff's which are identical
thoughts? (except for suggesting tiles which confused my designer guys
completely - they already are trying to work out why I am "designing new
HTML elements")
chanoch
--
Eddie Bush
Craig R. McClanahan
2002-10-16 21:09:52 UTC
Permalink
Date: Wed, 16 Oct 2002 20:10:47 +0100
Subject: Re: using OR condition with logic tags
however, this is quite ugly - you end up having to write two outputs for
what is basically the same problem, hence the reference to OR.
That means maintaining two Stuff's which are identical
thoughts? (except for suggesting tiles which confused my designer guys
completely - they already are trying to work out why I am "designing new
HTML elements")
Again using JSTL (Servlet 2.3 / JSP 1.2 container is required), you can
use the "||" operator to implement an OR:

<c:if test="${(foo == '1') || (foo == '2')}"/>
... stuff when foo is 1 or 2 ...
</c:if>

The expression language in JSTL 1.0 (and also in JSP 2.0, where you can
even use it in template text) is likely to become a JSP page author's best
friend. But if you're stuck on a Servlet 2.2 / JSP 1.1 based server,
you're best bet is probably to write your own custom tag that implements
the test you are after.
chanoch
Craig
----- Original Message -----
Sent: Tuesday, October 15, 2002 11:26 PM
Subject: Re: using OR condition with logic tags
Post by Sukhenko, Mikhail (Contr)
<logic:equal name="foo" value="1">
<!-- Stuff for when foo == 1 -->
</logic:equal>
<logic:equal name="foo" value="2">
<!-- Stuff for when foo == 2 -->
</logic:equal>
-- OR -- JSTL Approach 1
<c:choose>
<c:when test="${foo == 1}">
<!-- Stuff for when foo == 1 -->
</c:when>
<c:when test="${foo == 2}">
<!-- Stuff for when foo == 1 -->
</c:when>
</c:choose>
-- OR -- JSTL Approach 2
<c:choose>
<c:when test="${foo == 1}">
<!-- Stuff for when foo == 1 -->
</c:when>
<c:otherwise>
<!-- Stuff for when foo == 1 -->
</c:otherwise>
</c:choose>
Post by Sukhenko, Mikhail (Contr)
Hey, guys!
Do any of you know how to set up an OR condition with logic:equal tags?
<logic:equal name="foo" value="1"> OR <logic:equal name="foo" value="2">
Thanks
--
Eddie Bush
--
--
Sukhenko, Mikhail (Contr)
2002-10-16 20:35:44 UTC
Permalink
Hey, guys!
Do any of you know how to set up an OR condition with logic:equal tags?
i.e. :

<logic:equal name="foo" value="1"> OR <logic:equal name="foo" value="2">

Thanks
Loading...