Have you tried swapping the order of the <script>s? Also, are you sure you don't have a parse error? (can you read the 'info' global var in your browser's dev tools? particularly, double-check that getCurrentUser().getEmail() doesn't contain a newline; you might want to use a JSON API to generate your JS object literal, such as AutoBeans, javax.json, Jackson, org.json, etc.)
On Saturday, December 15, 2012 5:27:49 AM UTC+1, dhoffer wrote: > > I'm following the example given here > https://developers.google.com/web-toolkit/articles/dynamic_host_page of > passing a global info javascript variable back to the GWT app when it > loads. E.g. > > // In GwtHostingServlet's doGet() method... > writer.append("<html><head>"); > writer.append("<script type=\"text/javascript\" > src=\"sample/sample.nocache.js\"></script>"); > > // Open a second <script> tag where we will define some extra data > writer.append("<script type=\"text/javascript\">"); > > // Define a global JSON object called "info" which can contain some simple > key/value pairs > writer.append("var info = { "); > > // Include the user's email with the key "email" > writer.append("\"email\" : \"" + userService.getCurrentUser().getEmail() + > "\""); > > // End the JSON object definition > writer.append(" };"); > > // End the <script> tag > writer.append("</script>"); > writer.append("</head><body>Hello, world!</body></html>"); > > Then in my GWT app's EntryPoint class I have: > > public static native String getEmail() /*-{ > return $wnd.info['email']; > }-*/; > > However when the app runs I get an exception saying: > > $wnd.info is undefined > > I've tried $doc but got the same error. I also tried window and document > but then it says document.info is undefined. What am I doing wrong? > > -Dave > -- 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/-/3DG_kMwl8eAJ. 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.
