You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Wendy Smoak <We...@asu.edu> on 2002/10/08 20:46:42 UTC

Do something when null _or_ blank?

I just wrote this:

<logic:notEqual name="resView" property="personBirthDate" value="">
  <bean:write name="resView" property="personBirthDate" />
</logic:notEqual>
<logic:equal name="resView" property="personBirthDate" value="">
  --
</logic:equal>

What I really need is to print out the birthDate property if it's not blank
and not null, otherwise, print the '--'.  Can I combine notEqual and
present? [implied question:  HOW?]

Also, the above seems to me the equivalent of writing:

if ( something.equals("") )
  //do one thing;

if ( !something.equals("") )
  System.out.println(something);

which is downright PAINFUL to look at.

I tried to look at the generated JSP, but I couldn't find the translation of
the logic:equal/notEqual tags in there.  I guess I just want to know that
the code isn't calling resView.getPersonBirthDate() multiple times.  Can I
rest assured that the generated code is as efficient as possible?

Any suggestions appreciated!

-- 
Wendy Smoak
http://sourceforge.net/projects/unidbtags 

Re: Do something when null _or_ blank?

Posted by John Owen <jo...@hotmail.com>.
Maybe you should use <logic:greaterThan name="resView"
property="personBirthDate" value="">.
----- Original Message -----
From: "Wendy Smoak" <We...@asu.edu>
To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
Sent: Tuesday, October 08, 2002 1:46 PM
Subject: Do something when null _or_ blank?


>
> I just wrote this:
>
> <logic:notEqual name="resView" property="personBirthDate" value="">
>   <bean:write name="resView" property="personBirthDate" />
> </logic:notEqual>
> <logic:equal name="resView" property="personBirthDate" value="">
>   --
> </logic:equal>
>
> What I really need is to print out the birthDate property if it's not
blank
> and not null, otherwise, print the '--'.  Can I combine notEqual and
> present? [implied question:  HOW?]
>
> Also, the above seems to me the equivalent of writing:
>
> if ( something.equals("") )
>   //do one thing;
>
> if ( !something.equals("") )
>   System.out.println(something);
>
> which is downright PAINFUL to look at.
>
> I tried to look at the generated JSP, but I couldn't find the translation
of
> the logic:equal/notEqual tags in there.  I guess I just want to know that
> the code isn't calling resView.getPersonBirthDate() multiple times.  Can I
> rest assured that the generated code is as efficient as possible?
>
> Any suggestions appreciated!
>
> --
> Wendy Smoak
> http://sourceforge.net/projects/unidbtags
>

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


Re: Do something when null _or_ blank?

Posted by Kris Schneider <kr...@dotech.com>.
Wendy,

If you're using a JSP 1.2 container, you might want to check out JSTL:

<c:choose>
  <c:when test="${empty resView.personBirthDate}">
    --
  </c:when>
  <c:otherwise>
    <c:out value="${resView.personBirthDate}"/>
  </c:otherwise>
</c:choose>

Or even just:

<c:out value="${resView.personBirthDate}" default="--"/>

The difference is that the second approach makes a distinction between the 
empty string and null (I think). This is from memory, but you get the idea...

Quoting Wendy Smoak <We...@asu.edu>:

> 
> I just wrote this:
> 
> <logic:notEqual name="resView" property="resView" value="">
>   <bean:write name="resView" property="personBirthDate" />
> </logic:notEqual>
> <logic:equal name="resView" property="personBirthDate" value="">
>   --
> </logic:equal>
> 
> What I really need is to print out the birthDate property if it's not blank
> and not null, otherwise, print the '--'.  Can I combine notEqual and
> present? [implied question:  HOW?]
> 
> Also, the above seems to me the equivalent of writing:
> 
> if ( something.equals("") )
>   //do one thing;
> 
> if ( !something.equals("") )
>   System.out.println(something);
> 
> which is downright PAINFUL to look at.
> 
> I tried to look at the generated JSP, but I couldn't find the translation
> of
> the logic:equal/notEqual tags in there.  I guess I just want to know that
> the code isn't calling resView.getPersonBirthDate() multiple times.  Can I
> rest assured that the generated code is as efficient as possible?
> 
> Any suggestions appreciated!
> 
> -- 
> Wendy Smoak
> http://sourceforge.net/projects/unidbtags 
> 

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

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