You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Yariel Ramos Moreno <yr...@ceis.cujae.edu.cu> on 2006/03/23 06:01:12 UTC

Troubles with comparisons using logic tags

Hello:

I'm having some problems with comparisons using logic tags in Struts 1.1. There is more than 12 h that I'm trying to resolve it... and nothing.

I am passing 2 variables by session:
    niCount = 10
    viewed = 3 or 21 (I'm trying with this 2 values)

Then I'm doing this:

<logic:lessEqual scope="session" name="niCount" value="viewed">
    .... some code here ...
</logic:lessEqual>

<logic:lessThan scope="session" name="viewed" value="niCount">
    .... some code here ....
</logic:lessThan>

as result the code inside both conditions is executed... and if you look at both conditions, the variables are inverted. I have try all possible combination with the other tags and the evaluation is never correct (when I use logic:greaterThan or logic:greaterEqual, the code in it's body is never excecuted).

I don't know what can I do.

Thanks in advance,

Yariel.

Re: Troubles with comparisons using logic tags

Posted by Rahul Akolkar <ra...@gmail.com>.
On 3/23/06, Yariel Ramos Moreno <yr...@ceis.cujae.edu.cu> wrote:
> Hello:
>
> I'm having some problems with comparisons using logic tags in Struts 1.1. There is more than 12 h that I'm trying to resolve it... and nothing.
>
> I am passing 2 variables by session:
>    niCount = 10
>    viewed = 3 or 21 (I'm trying with this 2 values)
>
<snip/>

Many of the logic tags have been deprecated in favor of JSTL tags. The
comparison tags fall in this category.

If possible, switch to using JSTL, like so:

<c:if test="${sessionScope.niCount le sessionScope.viewed}">
  ... some code here ....
</c:if>

<c:if test="${sessionScope.viewed lt sessionScope.niCount}">
  ... some (hopefully other ;-) code here ....
</c:if>

even better, use <c:choose> since the two conditions are complementary.

If switching is not possible ...


> Then I'm doing this:
>
> <logic:lessEqual scope="session" name="niCount" value="viewed">
>    .... some code here ...
> </logic:lessEqual>
>
> <logic:lessThan scope="session" name="viewed" value="niCount">
>    .... some code here ....
> </logic:lessThan>
>
> as result the code inside both conditions is executed... and if you look at both conditions, the variables are inverted. I have try all possible combination with the other tags and the evaluation is never correct (when I use logic:greaterThan or logic:greaterEqual, the code in it's body is never excecuted).
>
<snap/>

Thats because the "value" attribute is passed the literal "viewed" in
the first case, leading to a String comparison. If you're able to use
EL, pass "${sessionScope.viewed}" instead (if not, a runtime
expression).

-Rahul


> I don't know what can I do.
>
> Thanks in advance,
>
> Yariel.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org