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 page
private native JsArrayExt<People> getRecommendedFriends()/*-{
    return $wnd.rcmdFriends;
}-*/;

@Override
public 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 post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to