To clarify my challenge a bit further. 1) I am populating a map with GwtStock objects - java code 2) Assigning a function that returns the map to a javascript function - java/javascript code 3) Returning that map from the javascript variable - javascript/java code
What should be a JavaScriptObject and JsArray object here? Cannot have GwtStock extending JavaScriptObject since I am instanciating them in java and that is not allowed for JavaScriptObjects. Should I have some additional wrapper class, GwtStockImp that contains GwtStock object? Should there be a java method in java code to convert map to JsArray before proceeding to the 2 step or should I simply have a return type of the function related to step 3 as JsArray? Thanks again. On 16 Feb., 18:01, denis56 <[email protected]> wrote: > Thanks. Is there a tutorial on JavaScriptObject and JsArray somewhere > that you know of? I have already read the jsni chapter in "GWT in > Action" but still have trouble to understand how wrap java objects > and java collections. > > In my particular case I have 3 methods (below). I guess that there is > no magic involved so that changing return type of getMapJs() to > JsArray<JavaScriptObject> would not work. > > On the other hand, I tried printing out the return value of > $wnd.__getMapJs() and that turns to be a huge JavaScript Object and I > have no idea how to iterate through it. So an example will help > tremendously. > > public Map<Long, GwtStock> getMap() { > return stockMap; > } > > public native Map<Long, GwtStock> getMapJs() /*-{ > return $wnd.__getMapJs(); > }-*/; > > public native void setUpJavaScriptApis(MapTest x) /*-{ > $wnd.__getMapJs = function() { > return [email protected]::getMap()(); > }; > }-*/; > > On 16 Feb., 02:54, Shawn Brown <[email protected]> wrote: > > > Hi, > > > > I am struggling with return types in methods implementing native > > > javascript interfaces. Returning strings is no problem, but calling a > > > method that returns a map > > > > public native Map<Long, GwtStock> getMap() /*-{ > > > return $wnd.parent.__getMap(); > > > }-*/; > > > > works only in hosted mode (!) and either throws a classcast exception > > > or returns null. > > > I don't know how to return a Map directly but you could try to return > > a JavaScriptObject > > > seehttp://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/g... > > seehttp://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=goog... > > > or what about: > > > JavaScript Overlay Types > > > Suppose you're happily using JSNI to call bits of handwritten > > JavaScript from within your GWT module. It works well, but JSNI only > > works at the level of individual methods. Some integration scenarios > > require you to more deeply intertwine JavaScript and Java objects -- > > DOM and JSON programming are two good examples -- and so what we > > really want is a way to interact directly with JavaScript objects from > > our Java source code. In other words, we want JavaScript objects that > > look like Java objects when we're coding. > > > GWT 1.5 introduces JavaScript overlay types to make it easy to > > integrate entire families of JavaScript objects into your GWT project. > > > seehttp://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=goog... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
