At 02:59 PM 11/18/99 -0800, Tom Christ wrote:
>I am trying to test in the onWebEvent of my search button whether or not
>the user
>entered anything into a particular field. I have tried:
>
>----------------
>CSpDisplayField dfDate1 = getDisplayField("FormData_Date1");
>if (dfDate1.getValue().isNull()) ...
>----------------
>
>and
>
>----------------
>CSpDisplayField dfDate1 = getDisplayField("FormData_Date1");
>String strStartDate = dfDate1.getValue().toString();
>if (strStartDate == "") ...
Oh, how many times has each of us done this.
== is object equality, i.e., is strStartDate the same object as a literal
String object whose value is "".
This will always be false because these are different objects.
You want to test value equality:
if(strStartDate.equals(""))
I use an all-purpose utility routine:
/**
* This method checks for a blank or empty object
*
* @param objecttocheck - The Object to check
* @return boolean - true if Object is blank or empty.
*/
//*********************************************************************
//*************************************************************************
public static boolean blankObject(Object objecttocheck) throws
Exception
{
try
{
//* make sure Object is not null
if (objecttocheck == null) return(true);
if (objecttocheck instanceof CSpNull) return (true);
if (objecttocheck instanceof CSpValue)
{
//* convert to String
objecttocheck = (Object) objecttocheck.toString();
} //(if objecttocheck instanceof CSpValue)
if (objecttocheck instanceof String)
{
//* make sure object is not blank
if (((String) objecttocheck).compareTo(" ")<0)
{
return(true);
} //if (objecttocheck.compareTo(" ")<0)
else return(false);
} //if (objecttocheck instanceof String)
else return(false);
} //try
catch (Exception ex)
{
CSpLog.send("NetDynamicsUtility",
CSpLog.ERROR,"blankObject, unexpected Exception: " +ex);
throw(ex);
} //catch
} // public static boolean blankObject(Object
objecttocheck) throws Exception
-- Curt Springer, Team ND
>----------------
>
>These both evaluate to FALSE whether data is entered or not. This is for
>a search page, and I'm using ND 4.1.3.
>
>Thanks,
>Tom
>
>_________________________________________________________________________
>
>For help in using, subscribing, and unsubscribing to the discussion
>forums, please go to: http://www.netdynamics.com/support/visitdevfor.html
>
>For dire need help, email: [EMAIL PROTECTED]
_________________________________________________________________________
For help in using, subscribing, and unsubscribing to the discussion
forums, please go to: http://www.netdynamics.com/support/visitdevfor.html
For dire need help, email: [EMAIL PROTECTED]