Monday, August 2, 2010

Re: JSONP: Overlays with Optional Attributes (HostedModeException's), How?

1) This HostedModeException is very annoying. Null (or in JavaScript terms 'undefined') is a valid value for my JavaScript/JSON attributes. I want a way where if the darn thing is undefined return null... don't throw a HostedModeException  - I also tried in jsni if(this.attribute){ return this.attribute; } else { return undefined } but the exception is still thrown.

in your Jsni instead of

if (this.attribute) { return this.attribute; } else { return undefined; }

try

if (this.attribute) { return this.attribute; } else { return null; }

In javascript, null and undefined are two differente things. When something is null, this means that an variable is defined and its value is null; If something is undefined that means there is no variable with that name.

the statment: "if (this.attribute)" works because when in a boolean context, undefined is evaluated to false. Just like C where 0 is false and everything else is true.

To solve the int problem, try to change the return type to "Object" and then check if the returned value is null. There is no way to return "null" in java if the return type of a method is a "primitive int";

I belive that since you are returning null from JSNI, the HostedMode will be smart enough to cast "javascript null" to "java null". :)
 
2) There is no documentation about how this will behave in production? Will it just return null? I don't know how I can ensure consistency between dev and production modes :'(

In production mode the javascript rules applies, so this probably will trigger an error in your browser. When using JSNI method is necessary to think in two different worlds (java and javascript). Check this link, maybe will help with the javascript type system: http://www.java2s.com/Tutorial/JavaScript/0100__Number-Data-Type/PrimitiveTypes.htm
 

Hope it helps.
--
André Moraes
Analista de Desenvolvimento de Sistemas
andrebq@gmail.com
http://andredevchannel.blogspot.com/

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment