Discussion:
Test for blank or null string in Jx
footh
2005-07-22 17:52:54 UTC
Permalink
This seems like it should be easy but I've tried a
million different combinations and I can't seem to get
a jx if tag to test for a blank or null string.

Can someone point me in the right direction?



__________________________________
Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mailtour.html
Mark Lundquist
2005-07-22 17:57:31 UTC
Permalink
Post by footh
This seems like it should be easy but I've tried a
million different combinations and I can't seem to get
a jx if tag to test for a blank or null string.
Can someone point me in the right direction?
Been there, felt the pain. I don't know why it doesn't "just work" the
way you would expect.

Anyway, this will work

<jx:if test="isEmpty (theString)">

cheers,
—ml—
footh
2005-07-22 18:42:15 UTC
Permalink
Thanks for the reply but still no luck using this
(with a param that is null):

<jx:if test="isEmpty (${mynullparam})">

I even tried:

<jx:if test="isEmpty (null)">
and
<jx:if test="isEmpty ('')">

Both resolve to false. Additionally, I have a
parameter that I know I'm passing as a blank string
(""). And when I do this:

<jx:if test="${myblankparam} == ''">

It resolves to true as expected. However, when I do
this:

<jx:if test="${myparam} != ''">

It still resolves to true. This is driving me crazy.
Any other suggestions?
Post by Mark Lundquist
Post by footh
This seems like it should be easy but I've tried a
million different combinations and I can't seem to
get
Post by footh
a jx if tag to test for a blank or null string.
Can someone point me in the right direction?
Been there, felt the pain. I don't know why it
doesn't "just work" the
way you would expect.
Anyway, this will work
<jx:if test="isEmpty (theString)">
cheers,
—ml—
---------------------------------------------------------------------
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
Mark Lundquist
2005-07-22 18:45:04 UTC
Permalink
Post by footh
Thanks for the reply but still no luck using this
<jx:if test="isEmpty (${mynullparam})">
<jx:if test="isEmpty (null)">
and
<jx:if test="isEmpty ('')">
Sorry, my bad... the function is 'empty', not 'isEmpty'! I remember
now that I'm looking at it in email :-/

—ml—
footh
2005-07-22 19:23:38 UTC
Permalink
Ugh...still the same problem. Would you expect this
to work?

<jx:if test="empty (null)">

Because that returns false. Same with this:

<jx:if test="empty ('')">

I searched all the samples for the text "empty(" and I
can't seem to find any examples. Any other
suggestions? I've spent way too much time on such a
simple logic statement. Doh!
Post by Mark Lundquist
Post by footh
Thanks for the reply but still no luck using this
<jx:if test="isEmpty (${mynullparam})">
<jx:if test="isEmpty (null)">
and
<jx:if test="isEmpty ('')">
Sorry, my bad... the function is 'empty', not
'isEmpty'! I remember
now that I'm looking at it in email :-/
—ml—
---------------------------------------------------------------------
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
JD Daniels
2005-07-22 21:37:15 UTC
Permalink
Hmm. to my way of thinking you need two checks, because null is not the
same as ''

<jx:if test="$var!=null">
<jx:if test="empty($var)">
var is empty
</jx:if>
var is null
</jx:if>
Post by footh
Ugh...still the same problem. Would you expect this
to work?
<jx:if test="empty (null)">
<jx:if test="empty ('')">
I searched all the samples for the text "empty(" and I
can't seem to find any examples. Any other
suggestions? I've spent way too much time on such a
simple logic statement. Doh!
Post by Mark Lundquist
Post by footh
Thanks for the reply but still no luck using this
<jx:if test="isEmpty (${mynullparam})">
<jx:if test="isEmpty (null)">
and
<jx:if test="isEmpty ('')">
Sorry, my bad... the function is 'empty', not
'isEmpty'! I remember
now that I'm looking at it in email :-/
—ml—
---------------------------------------------------------------------
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
---------------------------------------------------------------------
Mark Lundquist
2005-07-22 21:52:56 UTC
Permalink
Post by JD Daniels
Hmm. to my way of thinking you need two checks, because null is not
the same as ''
<jx:if test="$var!=null">
<jx:if test="empty($var)">
var is empty
</jx:if>
var is null
</jx:if>
no, empty( ) returns true for null (see
http://jakarta.apache.org/commons/jexl/reference/syntax.html).

—ml—
footh
2005-07-22 20:37:51 UTC
Permalink
Trying a million more combinations, I finally figured
it out. These both return true (for a null param and
blank string param respectively):

<jx:if test="${empty(mynullparam)}">
<jx:if test="${empty(myblankparam)}">

Also, the problems I was having comparing params with
"==" and "!=" operators was due to the fact that they
were strings. I forgot that when dealing with strings
in java, one should use the "equals()" function.

Ex.

<jx:if test="${myblankparam.equals(''}">
resolves to true

<jx:if test="${mynullparam.equals(NULL}">
doesn't work...probably hits a null pointer exception
the generator

<jx:if test="${mynullparam == NULL}">
resolves to true

Another key thing I was missing is I was only putting
the brackets around the parameter, not the whole
expression. Oh well, lesson learned. Thanks for the
help.
Post by footh
Ugh...still the same problem. Would you expect this
to work?
<jx:if test="empty (null)">
<jx:if test="empty ('')">
I searched all the samples for the text "empty(" and
I
can't seem to find any examples. Any other
suggestions? I've spent way too much time on such a
simple logic statement. Doh!
Post by Mark Lundquist
Post by footh
Thanks for the reply but still no luck using
this
Post by Mark Lundquist
Post by footh
<jx:if test="isEmpty (${mynullparam})">
<jx:if test="isEmpty (null)">
and
<jx:if test="isEmpty ('')">
Sorry, my bad... the function is 'empty', not
'isEmpty'! I remember
now that I'm looking at it in email :-/
—ml—
---------------------------------------------------------------------
Post by footh
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
---------------------------------------------------------------------
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Mark Lundquist
2005-07-22 21:51:53 UTC
Permalink
Post by footh
Trying a million more combinations, I finally figured
it out. These both return true (for a null param and
<jx:if test="${empty(mynullparam)}">
<jx:if test="${empty(myblankparam)}">
Yes, that should be correct: see
http://jakarta.apache.org/commons/jexl/reference/syntax.html
Post by footh
Also, the problems I was having comparing params with
"==" and "!=" operators was due to the fact that they
were strings. I forgot that when dealing with strings
in java, one should use the "equals()" function.
well hmmmm... according to the doc referenced above, == and != use Java
equals().

—ml—
Andrew Franz
2005-07-24 17:04:14 UTC
Permalink
The following is JSP/JSTL equivalent to test for null parameters or
database columns:
<c:when test="${empty rs.foo}">
<c:when test="${empty param.foo}">
Post by footh
Thanks for the reply but still no luck using this
<jx:if test="isEmpty (${mynullparam})">
<jx:if test="isEmpty (null)">
and
<jx:if test="isEmpty ('')">
Both resolve to false. Additionally, I have a
parameter that I know I'm passing as a blank string
<jx:if test="${myblankparam} == ''">
It resolves to true as expected. However, when I do
<jx:if test="${myparam} != ''">
It still resolves to true. This is driving me crazy.
Any other suggestions?
Post by Mark Lundquist
Post by footh
This seems like it should be easy but I've tried a
million different combinations and I can't seem to
get
Post by footh
a jx if tag to test for a blank or null string.
Can someone point me in the right direction?
Been there, felt the pain. I don't know why it
doesn't "just work" the
way you would expect.
Anyway, this will work
<jx:if test="isEmpty (theString)">
cheers,
—ml—
---------------------------------------------------------------------
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
---------------------------------------------------------------------
Loading...