Pathfinder Development

Agile Ajax

GWT with JSONP

I've been looking to add to my JSONP series with some examples using GWT. Dan Morrill over at Google has beaten me to the punch with an article on just this subject. The code for it is rather straightforward, but there are a few sticky bits that make it a little less so: 

I spent quite a while debugging this, until I finally asked Scott Blum, a GWT Engineer.  Scott merely asked a question:  "Was the array created in the same window in which you're testing it?"

What Scott knew that I did not, is that the JavaScript classes (like Array) corresponding to the primitive types are constructed along with the window object.  Because JavaScript is a prototype-oriented language, the "classes" are really just object instances with special names.  These two issues combine to reveal a subtle but important issue: the Array objects from two different windows are not the same object!  The expression "x instanceof y" in JavaScript boils down to something like this pseudocode:  "if the 'prototype' property of 'x' is the same object as 'y', return true, else return false".

At this point, you may be wondering how multiple windows entered the discussion.  The key is the $wnd variable, which points to the hidden iframe in which the application's GWT code is loaded.  The DOM object in GWT, however, points to the parent window's document object; after all, your application code is interested in manipulating the browser window, not GWT's hidden iframe.  As a result, in the code above, the <script> tag is added to the parent window, while the code using it resides in a different iframe.  This means that the object is created in a window different from where the "instanceof" checks are made, thus causing the issue above.

The solution Dan chose was to add the <script> tag to the iframe that contains the GWT code.

Of course the new "cross site" compilation option produces code that loads directly into the main page, so this hack may not in fact be necessary.

Technorati Tags: ajax, gwt, jsonp

Topics: GWT, JSON

Comments

None so far.

Leave a comment

Powered by WP Hashcash

About Pathfinder

We design and build extraordinary applications for companies looking to make the next great idea a reality. learn more

Topics

.NET 3d 3D GPS Accessibility actionscript activerecord Add new tag ADO.NET Entity Framework Adobe Adobe AIR Advertising agile Agile Development AIR Ajax Ajax Applications Ajax Bookmarking Ajax Components Ajax Development Ajax Examples Ajax Frameworks Ajax Intervention Ajax libraries AJAX Obfuscation Ajax Performance Ajax Products Ajax Tools Ajax Widgets Analysis Android Announcement Announcements antennae Apollo Application Architecture Application Development ASP.NET Asynchronous Processing awards Back Button Benchmarking Best Practices BitmapData.draw BJAX Blaze Advisor blog blogging Books Browsers Business Reasons for Ajax Business Rules C# Canvas Case Studies Chicago CMS COBOL Code Generation Color COMET Conference Consistency Content Management CRM CSS Custom Flex Component Degrafa Design Design Patterns Desktop Desktop RIA Developer's Notebook Diagnose Dojo Domain Knowledge Drools Echo2 Echo3 Editorial ERP Ethnographic Research Ext JS Facebook FileReference Firefox Firefox Extensions Flash flash awards flash player 10 Flex flexunit Flow Frameworks front end front end development Games Gauge Component Git Google Google calendar Google Gears Grails Graphics Greasemonkey Groovy GStreamer Gwittir GWT Healthcare Hibernate IDE Ideation IE IE6 IE7 IE8 ILOG JRules Information Architecture Innovation Instructional Design Interaction Design Interview iPhone iTunes Java Javascript JavaScript frameworks Javascript Libraries JBoss Rules Jess Jetty JIT Jobs jQuery JSF JSON JSR-94 Lazlo Legacy Systems lightweight LinkedIn LINQ Logical Model and Conceptual Model Low Pro Mac Mash Note Mashups MetaWidget Methodology Microformats Microsoft Mobile Mootools Mozilla Music MVC MySql Object-Oriented Object Relation Mapping (ORM) Office OOP Open Screen Open Source Opera ORM pagination Pair Programming papervision3d Patterns Peer Creation Performance Personas PHP plugin preloader process Web/Tech Progressive Enhancement Project Website Prototype Prototyping PV3D QA qooxdoo Radiant CMS rails Really Simple History References Requirements Requirements Alice Toth Requirements Visualization Restlet RETE Review Rich Interactions ruby Ruby on Rails SaaS Safari San Francisco Scalability Scenarios Scriptaculous SDLC Search Security Selenium Semantic web SEO Server Side Silverlight SOA Social Networking Software Processes Songbird SpiderMonkey Sprajax Spreadsheets Standards STI Story Telling Struts Tamarin Task Flows Test Driven Development Testing Tilt Component Tools TraceMonkey Training Trends Tumblr Tutorial Tutorials Unit Tests Usability Usability Testing User Experience user experience design user interface User Interface Standards User Research UXD Video Visualization VLC Volta Web/Tech Web 2.0 Web Design Web Development Webkit Weblogs Web Services Web Standards Widgets will_paginate Windows Wireframes WordPress workflow XML XML Metadata XUL Yahoo Map AS3 API Zeigarnik Zeigarnik Effect ZK

WordPress

Comments about this site: info@pathf.com


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser