I have written a simple method to check date variable is null or not. Here is following code.
function dValidateDate()
{
var dDate = new Date();
if(dDate == null)
{
application.out(“Date Is Null”);
}
else
{
application.out(dDate);
}
}
I was excepting it will print Date but it is returning 2008-08-14 16:44:42,979 ERROR [AWT-EventQueue-0] com.servoy.j2db.util.Debug - Throwable java.lang.NullPointerException .
If i am changing condition like this.
//if(dDate == null)
if(dDate == “”)
It is working. I don’t think it is standard way of checking null.
if(dDate == null) Condition working well into Servoy 3.5.x versions. But it is not working in Servoy 4.0. If any buddy switching from Servoy 3.5.x to Servoy 4.0 and used this condition for checking null in date variable. There would a problem for developer. What we can do for avoiding this kind of problems?.
In fact in JavaScript you should really never use “==” unless you specifically want to check for falsy/truthy values instead of a specific value. Same goes for “!”.
IT2Be:
function dValidateDate()
{
var dDate = new Date();
if(!dDate)
{
application.output(“Date Is Null”);
}
else
{
application.output(dDate);
}
}
Thanks Marcel, I already tried it, it is working.
jbader:
In fact in JavaScript you should really never use “==” unless you specifically want to check for falsy/truthy values instead of a specific value. Same goes for “!”.