On 3 mar, 14:07, mP <[email protected]> wrote:
> Your snippet to create a New Person instance in jsni will not work.
> Whilst the compiler will not report a compile time error,your code
> will fail whenver some java code attempts to do anything with that
> instance.
>
> There are many wrong assumptions wwirh your advice...
> @ Properties and method names get mangled - you must jsni styled
> references to these rather than literals.
Wrong; in that specific case, that's the other way around: wrapping a
JavaScript object in Java code. The code is not trying to get/set a
Java field's value from JavaScript, but getting/setting a JavaScript
property from Java.
However, I would have wrote the test() method in pure Java:
private Person test() '
Person p = JavaScriptObject.createObject().cast();
o.setUserName("some username");
return o;
}
> @ The prototype is not set so any attempt to call real Person methods
> will also fail.
Wrong (sort of).
The Person Java class, can have any methods you like, provided they
are 'final'.
The corresponding/wrapped JS object may have methods too, either as
"own properties" or inherited from its prototype (toString() for
instance, as the prototype defaults to Object.prototype in the given
code sample) and you'd call them using JSNI, the same way get/
setUserName accesses a property.
Note that using the suggested approach of JavaScriptObject (JS overlay
types) doesn't preclude setting the native JS prototypes if you do
instantiate such overlay objects.
> Anything relati g to the type of the instance will
> also fail because the gwt emulation of java in is won't know what type
> your Person instance is.
Right, JS overlay types are just "syntactic sugar" to help you work
with "pure JS" objects from the Java world.
> @ All you hav achieved is to create a fake but broken javascript
> object that is telling the compiler it's a Person but it's not...
Wrong.
Maybe you should give a look at
http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&t=DevGuideOverlayTypes
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---