You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Wim Bervoets <wi...@iconmedialab.com> on 2002/04/02 17:00:51 UTC

testing on empty string or null with jstl

Hello,

I have the following code:

<c:choose>
<c:when test="(${param.yourName} != '') and (${param.yourEmail} != '') and
(${param.friendsEmail1} != '')">
	email something
</c:when>
<c:otherwise>
	[<c:out value="${param.yourName}"/>]
	[<c:out value="${param.yourEmail}"/>]
	[<c:out value="${param.friendsEmail1}"/>]
	[<%=request.getParameter("yourName")%>]
	[<%=request.getParameter("yourEmail")%>]
	[<%=request.getParameter("friendsEmail1")%>]		
</c:otherwise>
</c:choose>

If the request paramaters are not empty I would like to send a mail - eg.
execute the when.
- otherwise execute the otherwise.

Problem I have is that c:otherwise is always executed - even when the
parameters are set (I can see they are set because of the c:out's)

So how can I check for an empty string or null ? ${param.yourName} != null
or ${param.yourName} != '' doesn't work !
I'm using resin 2.0.5  - maybe it has something todo with the forEach
problem that was fixed recently in resin 2.1.0 ?

Thanks
Wim







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


Re: testing on empty string or null with jstl

Posted by Pedro Diaz <pe...@bancoval.es>.
Hi.

Try

<c:when test="${ (param.yourName != '') and (param.yourEmail != '') and
(param.friendsEmail1 != '') }">

instead of

<c:when test="(${param.yourName} != '') and (${param.yourEmail} != '') and
(${param.friendsEmail1} != '')">

Greetings

Wim Bervoets wrote:

> Hello,
>
> I have the following code:
>
> <c:choose>
> <c:when test="(${param.yourName} != '') and (${param.yourEmail} != '') and
> (${param.friendsEmail1} != '')">
>         email something
> </c:when>
> <c:otherwise>
>         [<c:out value="${param.yourName}"/>]
>         [<c:out value="${param.yourEmail}"/>]
>         [<c:out value="${param.friendsEmail1}"/>]
>         [<%=request.getParameter("yourName")%>]
>         [<%=request.getParameter("yourEmail")%>]
>         [<%=request.getParameter("friendsEmail1")%>]
> </c:otherwise>
> </c:choose>
>
> If the request paramaters are not empty I would like to send a mail - eg.
> execute the when.
> - otherwise execute the otherwise.
>
> Problem I have is that c:otherwise is always executed - even when the
> parameters are set (I can see they are set because of the c:out's)
>
> So how can I check for an empty string or null ? ${param.yourName} != null
> or ${param.yourName} != '' doesn't work !
> I'm using resin 2.0.5  - maybe it has something todo with the forEach
> problem that was fixed recently in resin 2.1.0 ?
>
> Thanks
> Wim
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
         ----------
             |  Pedro Javier Díaz
             |  Técnico de Alioth S.A.
             |
             |     "¿Y tú, te reunes o trabajas?"
              ------------------------------------



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


Re: testing on empty string or null with jstl

Posted by peter lin <pe...@labs.gte.com>.
according to the specs, I believe EL will evaulate null value to zero
length string.

if you treat zero length string and null as the same condition, does
that work for your situation? 

I'm a little confused by the example you provide. the first when checks
to make sure name and email are not null or zero length. the otherwise
is supposed to send an email. but who is it suppose to send it to? the
friend's email address?

if you use request.getParameter(string), you're going to get null
pointer error if no value was given. shouldn't the page display an error
message, since it doesn't have the email address to send a message. is
the friend's email a gauranteed value that is always present?

a bit more information would make it easier to diagnose.

peter


Wim Bervoets wrote:
> 
> Hello,
> 
> I have the following code:
> 
> <c:choose>
> <c:when test="(${param.yourName} != '') and (${param.yourEmail} != '') and
> (${param.friendsEmail1} != '')">
>         email something
> </c:when>
> <c:otherwise>
>         [<c:out value="${param.yourName}"/>]
>         [<c:out value="${param.yourEmail}"/>]
>         [<c:out value="${param.friendsEmail1}"/>]
>         [<%=request.getParameter("yourName")%>]
>         [<%=request.getParameter("yourEmail")%>]
>         [<%=request.getParameter("friendsEmail1")%>]
> </c:otherwise>
> </c:choose>
> 
> If the request paramaters are not empty I would like to send a mail - eg.
> execute the when.
> - otherwise execute the otherwise.
> 
> Problem I have is that c:otherwise is always executed - even when the
> parameters are set (I can see they are set because of the c:out's)
> 
> So how can I check for an empty string or null ? ${param.yourName} != null
> or ${param.yourName} != '' doesn't work !
> I'm using resin 2.0.5  - maybe it has something todo with the forEach
> problem that was fixed recently in resin 2.1.0 ?
> 
> Thanks
> Wim
> 
> --
> 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: testing on empty string or null with jstl

Posted by Lev Pelekh <pe...@digitalroot.com>.
Wim,

I am new to JSTL, but I seems to me that your test expressions is malformed.
According to A.2.1 of JSTL spec, mixing EL and text as part of an attribute
concatenates the text and the results of EL evaluation. Furthermore, I think
that only binary "and" operator is supported. Try using this expression in a
<c:out>. That may clarify what your test expression evaluates to.

Lev.




-----Original Message-----
From: Wim Bervoets [mailto:wim.bervoets@iconmedialab.com]
Sent: Tuesday, April 02, 2002 10:01 AM
To: 'taglibs-user@jakarta.apache.org'
Subject: testing on empty string or null with jstl


Hello,

I have the following code:

<c:choose>
<c:when test="(${param.yourName} != '') and (${param.yourEmail} != '') and
(${param.friendsEmail1} != '')">
	email something
</c:when>
<c:otherwise>
	[<c:out value="${param.yourName}"/>]
	[<c:out value="${param.yourEmail}"/>]
	[<c:out value="${param.friendsEmail1}"/>]
	[<%=request.getParameter("yourName")%>]
	[<%=request.getParameter("yourEmail")%>]
	[<%=request.getParameter("friendsEmail1")%>]
</c:otherwise>
</c:choose>

If the request paramaters are not empty I would like to send a mail - eg.
execute the when.
- otherwise execute the otherwise.

Problem I have is that c:otherwise is always executed - even when the
parameters are set (I can see they are set because of the c:out's)

So how can I check for an empty string or null ? ${param.yourName} != null
or ${param.yourName} != '' doesn't work !
I'm using resin 2.0.5  - maybe it has something todo with the forEach
problem that was fixed recently in resin 2.1.0 ?

Thanks
Wim







--
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>