You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jana Navaneethan <ja...@labs.gte.com> on 2002/12/04 23:23:42 UTC

if condition with "or"

Hi,
      I want to use <logic:equal> in my JSP to replace the following code.

if  (count = 0 || count = 2 || count = 4)
do something.....

How to achieve this using <logic:equal> By the count is index value of the
iterator i.e indexId.

Thanks in advance,
Jana.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: if condition with "or"

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 5 Dec 2002, Jim Collins wrote:

> >
> > This is one of the very large number of reasons that you should start
> > using JSTL if you can (i.e. you're on a Servlet 2.3/JSP 1.2 or later
> > container):
> >
> >   <c:if test="${(count == 0) || (count == 2) || (count == 4)}">
> >     ... do something ...
> >   </c:if>
> >
> Hi Craig I remember seeing one of you posts where you say you are against
> having java code in a JSP

That is correct.  However, the underlying issue is that embedding
scriptlets into JSP pages tempts you to put business logic there, not just
presentation logic.  If this logic is for managing the presentation only,
one could contend that the scriptlet equivalent:

  <% if ((count == 0) || (count == 2) || (count ==4)) { %>
    ... do something ...
  <% } %>

is not evil either (unless you're a zealot or something :-).

> but what is the difference between having a
> scriptlet or what you use above?
>

At the end of the day, we're building UIs that have dynamic content in
them.  Thus, at some level, we're going to need to do a little
"programming" in our pages, for things like conditionally including menu
options depending on who the user is.  The requirement to do this (for a
particular application design) is usually non-negotiable -- the question
is, what's the best way to implement it?

There's a continuum of complexity in expressions (whether they are Java
runtime expressions or EL expressions) and more general-purpose
computational structures.  What we'd generally like is a technology that
allows page authors to have enough capability to construct the dynamic
aspects of their pages, without giving them enough rope to hang
themselves.  Expression languages seem to be a reasonable compromise on
that ground.

Remember that most page authors will need just the simplest possible
expressions:

    <c:out var="${customer.address.city}"/>

which is just a syntactically different way of saying (with a Struts tag):

    <bean:write name="customer" property="address.city"/>

so we're already using *an* expression language syntax in Struts.
However, the EL defined by JSTL is substantially better.  I want Struts
users to migrate, rather than trying to enhance the Struts proprietary
syntax to match the power.  And I don't want a page author to have to know
anything at all about Java in the process (which is why the EL syntax for
accessing data was very deliberately modeled after JavaScript, which many
page authors are already familiar with).

> Regards
>
> Jim.

Craig



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: if condition with "or"

Posted by Andrew Hill <an...@gridnode.com>.
<snip>
what is the difference between having a scriptlet or what you use above?
</snip>

Hehe I rather agree Jim!
(Mind you I am rather anti-JSP so my view is probably a bit biased!)

Your question reminds me of an old article I read several months ago by
Jason Hunter (author of the O'Rielly Servlet book) written back at the dawn
of time (or to be more precise in the year 2000).
http://www.servlets.com/soapbox/problems-jsp.html

The quote that stuck in my mind was:
<snip>
Someday there will be custom tags for doing these loops. And custom tags for
"if" checks too. And JSP pages may look like a grotesque Java reimplemented
with tags
</snip>

Hmmm??????

<c:if test="${(count == 0) || (count == 2) || (count == 4)}">
   ... do something ...
</c:if>






-----Original Message-----
From: Jim Collins [mailto:james.collins@blueyonder.co.uk]
Sent: Thursday, December 05, 2002 14:29
To: Struts Users Mailing List
Subject: Re: if condition with "or"



----- Original Message -----
From: "Craig R. McClanahan" <cr...@apache.org>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Thursday, December 05, 2002 12:20 AM
Subject: Re: if condition with "or"


>
>
> On Wed, 4 Dec 2002, Jana Navaneethan wrote:
>
> > Date: Wed, 4 Dec 2002 17:23:42 -0500
> > From: Jana Navaneethan <ja...@labs.gte.com>
> > Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> > To: Struts Users Mailing List <st...@jakarta.apache.org>
> > Subject: if condition with "or"
> >
> > Hi,
> >       I want to use <logic:equal> in my JSP to replace the following
code.
> >
> > if  (count = 0 || count = 2 || count = 4)
> > do something.....
> >
> > How to achieve this using <logic:equal> By the count is index value of
the
> > iterator i.e indexId.
> >
>
> This is one of the very large number of reasons that you should start
> using JSTL if you can (i.e. you're on a Servlet 2.3/JSP 1.2 or later
> container):
>
>   <c:if test="${(count == 0) || (count == 2) || (count == 4)}">
>     ... do something ...
>   </c:if>
>
Hi Craig I remember seeing one of you posts where you say you are against
having java code in a JSP but what is the difference between having a
scriptlet or what you use above?

Regards

Jim.
>
> > Thanks in advance,
> > Jana.
> >
>
> Craig
>



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: if condition with "or"

Posted by Jim Collins <ja...@blueyonder.co.uk>.
----- Original Message -----
From: "Craig R. McClanahan" <cr...@apache.org>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Thursday, December 05, 2002 12:20 AM
Subject: Re: if condition with "or"


>
>
> On Wed, 4 Dec 2002, Jana Navaneethan wrote:
>
> > Date: Wed, 4 Dec 2002 17:23:42 -0500
> > From: Jana Navaneethan <ja...@labs.gte.com>
> > Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> > To: Struts Users Mailing List <st...@jakarta.apache.org>
> > Subject: if condition with "or"
> >
> > Hi,
> >       I want to use <logic:equal> in my JSP to replace the following
code.
> >
> > if  (count = 0 || count = 2 || count = 4)
> > do something.....
> >
> > How to achieve this using <logic:equal> By the count is index value of
the
> > iterator i.e indexId.
> >
>
> This is one of the very large number of reasons that you should start
> using JSTL if you can (i.e. you're on a Servlet 2.3/JSP 1.2 or later
> container):
>
>   <c:if test="${(count == 0) || (count == 2) || (count == 4)}">
>     ... do something ...
>   </c:if>
>
Hi Craig I remember seeing one of you posts where you say you are against
having java code in a JSP but what is the difference between having a
scriptlet or what you use above?

Regards

Jim.
>
> > Thanks in advance,
> > Jana.
> >
>
> Craig
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: if condition with "or"

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 4 Dec 2002, Jana Navaneethan wrote:

> Date: Wed, 4 Dec 2002 17:23:42 -0500
> From: Jana Navaneethan <ja...@labs.gte.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: if condition with "or"
>
> Hi,
>       I want to use <logic:equal> in my JSP to replace the following code.
>
> if  (count = 0 || count = 2 || count = 4)
> do something.....
>
> How to achieve this using <logic:equal> By the count is index value of the
> iterator i.e indexId.
>

This is one of the very large number of reasons that you should start
using JSTL if you can (i.e. you're on a Servlet 2.3/JSP 1.2 or later
container):

  <c:if test="${(count == 0) || (count == 2) || (count == 4)}">
    ... do something ...
  </c:if>


> Thanks in advance,
> Jana.
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>