Date Validation Exception

Hi All,

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?.

Thanks
Prem

function dValidateDate()
{
var dDate = new Date();
if(dDate == null)
{
application.out("Date Is Null");
}
else
{
application.out(dDate);
}
}

This code seems fine, except for

application.out(…

This ought to be

application.output(

If that doesn’t solve the issue, please file a case in our support system.

Paul

pcm:
application.out(dDate);

Made a mistake writen a code over here. Actual code haves
This one

pbakker:
application.output(

but it is not working.

What happens when you do:

function dValidateDate()
{
var dDate = new Date();
if(!dDate)
{
application.output("Date Is Null");
}
else
{
application.output(dDate);
}
}

This may or may not be the issue here but FYI…

To check for the value null use

=== null

not

== null

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 “!”.

Thanks jbader, for valuable information.

Thanks
Prem

that null pointer is a bug in servoy/script engine will be fixed in 4.0.1

Hi Johan,

Thank, you people…

Thanks
Prem