Dev - Note on testing for null values in a form-widget use-when

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Dev - Note on testing for null values in a form-widget use-when

Leon Torres-2
Ever wondered why the following use-when returns true when the variable
"foo" isn't defined?

     use-when="foo==null"

This is due to the way beanshell works. When beanshell first encounters
an undefined variable such as "foo", it treats it as a "void". The
"void" type is not considered to be null,

     void == null : false
     void != null : true

You can see this for yourself with the following script:

     print("What is foo? " + foo);
     print("Is foo null? " + (foo==null));
     print("Is foo void? " + (foo==void));

So the lesson is to keep void in mind when writing a use-when condition.

I added this to the form widget cookbook, which can be found along with
other useful cookbooks here,

   http://www.opensourcestrategies.com/ofbiz/tutorials.php


- Leon
 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev