I think you have it wrong. I would do this, first, People must be a
JavaScriptObject not an interface:
public class People extends JavaScriptObject {
protected People(){}
public native final String image() /*-{
return this["image"];
}-*/;
public native final People image(String val) /*-{
this["image"] = val;
return this;
}-*/;
}
Then, I think you are wrong also in getRecommendedFriends(). It needs to be
final and to return a JsArray<People>
private native final JsArray<People> getRecommendedFriends()/*-{ return
$wnd.rcmdFriends;}-*/;
Other stuff I think it is OK. Than should work.
On Wednesday, December 5, 2012 6:05:43 AM UTC-2, Alex Luya wrote:
>
> I followed this article to use hostpage to pass an array to client:
>
> https://developers.google.com/web-toolkit/articles/dynamic_host_page
>
>
> Currently,I can see follow content in firebug
>
> <html style="overflow: hidden;"><head>...... <script
> type="text/javascript"> var
> rcmdFriends=[{"Name":"Friend-0","Image":"url"}];
> </script></head>......</html>
>
>
> Then I tried to use these code to get js variable(a json array actually)
> from hostpage and print it to user:
>
> //get array from host pageprivate native JsArrayExt<People>
> getRecommendedFriends()/*-{ return $wnd.rcmdFriends;}-*/;
> @Overridepublic void onModuleLoad(){ final FlowPanel fPanel = new
> FlowPanel(); JsArrayExt<People> channels = getRecommendedFriends(); for
> (int i = 0, len = channels.length(); i < len; i++) {
> //"print" name to user fPanel.add(new
> Label(channels.get(i).getName())); } RootPanel.get().add(fPanel);}
> //model definition @SingleJsoImpl(PeopleImpl.class) public
> interface People extends HasName { String getImage(); void
> setImage(String Image); }
>
>
> But got this eror:
>
> java.lang.ClassCastException: com.google.gwt.core.client.JavaScriptObject$
> cannot be cast to com.pkg.People
>
>
> Strangely,I can already see the length of "channels" is 1,and why do I get
> this casting error?How to solove this problem?
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/voU6DFKaC7oJ.
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.