This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Flex and the fly likes Null references for java numbers and flex Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Frameworks » Flex
Reply Bookmark "Null references for java numbers and flex" Watch "Null references for java numbers and flex" New topic
Author

Null references for java numbers and flex

Morten Franorge
Ranch Hand

Joined: Jul 29, 2005
Posts: 137
In our domain model, having a null value for certain numbers (Integer, Long and Double) have specific business meaning in our domain (different than 0). However, there is no way to represent nulls in action script. They are interpreted as NaN, but once a NaN is sent back to Java, it is not translated back to null. What is the best practise to handle this?


SCJP 1.4, SCBCD 1.3, SCBCD 5.0, SCEA J2EE, SCEA 5.0
Satish Kore
Author
Ranch Hand

Joined: Feb 10, 2004
Posts: 43
Hi Morten,

In ActionScript primitive types do not hold null value so anything that is Number,int or uint cannot hold null. Only Object or * type can hold null reference. There are two ways that I can see.

1. Simple approach would be just change type of ActionScript property from Number to Object and then if you assign null, it will be deserialized into null on java side.
2. Try not to use null as valid value, try using -1 or any negative value to represent your meaning.

Thanks,

Satish Kore
"Flex 3 with Java" @ packtpub.com and amazon.com
Morten Franorge
Ranch Hand

Joined: Jul 29, 2005
Posts: 137
Satish Kore wrote:Hi Morten,

In ActionScript primitive types do not hold null value so anything that is Number,int or uint cannot hold null. Only Object or * type can hold null reference. There are two ways that I can see.

1. Simple approach would be just change type of ActionScript property from Number to Object and then if you assign null, it will be deserialized into null on java side.
2. Try not to use null as valid value, try using -1 or any negative value to represent your meaning.

Thanks,


Option 2 require me to change the inherit functionality in my domain model, which does not sit well with the DDD. Option 1 makes the action script model sub optimal....hmmmm
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Null references for java numbers and flex
 
Similar Threads
Using Scanner to read one line at a time
doubt reg NaN (from JLS)
the output is Nan
definition of ordinal numbers
SCJP Coaching