struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Van Wart <>
Subject Re: The validwhen validation's treatment of null and empty string
Date Sat, 03 Jun 2006 03:14:23 GMT
Craig McClanahan wrote:
> You need to test for both conditions in the latter case, but the 
> particular
> approach you suggest above is not necessarily going to work.  You cannot
> reliably do "==" tests on strings if you are looking for equality -- you
> need to use the equals() function instead.
Not sure if I communicated this correctly, as I referenced the 
'validwhen' only in the subject and didn't refer to it in my message 
body (just to set the record straight I've been using Java for 6 years, 
4 years as a full-time job).  I wasn't sure about the expression 
language that the "validwhen" validator uses.  It doesn't look exactly 
like JSP EL, but in the JSP expression language you can do stuff like:

<c:if test="${empty property}">
  Hey, property is empty.

    and the test condition will be true if the following is true (in the 
Java language): ( property == null || property.equals( "" ) ).  Although 
this is only for java.lang.String objects.  Collection (List, Set, etc.) 
objects also work like collection.isEmpty().  BUT, the kind of 
expressions that the "validwhen" validator takes don't look like JSP EL, 
nor Java, and as all the examples seem to say stuff like

  <field name="property" depends="validwhen">
      <var-value>(property == null)</var-value>

  the reference to "null" kind of concerns me, as it's possible for the 
bean to use the empty string "" in its properties (at least, that's what 
I use in all my beans, including the reset() methods).

- Scott

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message