On Tue, 23 Apr 2002, Morgan Delagrange wrote:

> > > I was just wondering while reading the
> > specification - how do I test
> > > on something being not empty?
> > > 
> > > <c:if test="${!empty param.name}">
> > >    You specified a name.
> > > </c:if>
> > > 
> > > Is this correct?
> > 
> > Sure - or
> > 
> >   ${not empty param.name}
> 
> or ${param.name != null}

Careful with that, though.  A parameter isn't guaranteed to be null if a
user didn't specify it; empty text boxes typically come through as empty
strings ("").  So checks like

  <c:if test="${param.name != null}">
    You must specify a name
  </c:if>

are prone to errors; you should use

  <c:if test="${not empty param.name}">

instead.

Of course, "== null" and "!= null" are still useful when you want to check
specifically against Java null -- but this isn't usually what you want
with request parameters.

-- 
Shawn Bayern
"JSP Standard Tag Library"   http://www.jstlbook.com
(coming this summer from Manning Publications)


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to