GWT and Sencha GXT: FormPanel result fails

myystiqueen

New Member
TL/DR: How to load an XML response via \[code\]FormPanel\[/code\] reliably?We have a web application in GWT using Sencha GXT for most of the UI. We use a GXT \[code\]FormPanel\[/code\] to upload a file to a server-side script (which just echoes the file's contents) to get a local file's contents in JS. Eventually this can be done with FileReader, but obviously not in browsers that don't support that.The \[code\]FormPanel\[/code\] submits its form and loads the result in a hidden IFrame from which the contents are extracted with the following snippet (from \[code\]FormPanelImpl.class\[/code\]):\[code\]try { // Make sure the iframe's window & document are loaded. if (!iframe.contentWindow || !iframe.contentWindow.document) return null; // Get the body's entire inner HTML. return iframe.contentWindow.document.body.innerHTML;} catch (e) { return null;}\[/code\]We're loading an XML file that way and the problematic line is\[code\]return iframe.contentWindow.document.body.innerHTML;\[/code\]because the XML is loaded as XML (and thus not embedded in a HTML wrapper) in a few cases. I tried the following:[*]I used \[code\]Content-Type: text/html\[/code\] originally (oversight in the local PHP test script, error on my part in the production code). Worked in Firefox and Chrome but not in IE (9) where the XML was loaded as XML in the IFrame instead.[*]\[code\]Content-Type: application/xml\[/code\] which would be the correct one for the payload. Now it doesn't work anywhere because we now get the behaviour that originally only IE exhibited in Chrome and FF too.[*]\[code\]Content-Type: application/octet-stream\[/code\]: Not a good idea, it just downloads the file.[*]\[code\]Content-Type: text/plain\[/code\]: I was hoping this would always trigger the HTML/body wrapping and it does, but it also wraps everything in a \[code\]pre\[/code\] element so it now fails everywhere, but that at least reliably. Great.After a little digging I found out that apparently the GXT \[code\]FormPanel\[/code\] uses the same \[code\]FormPanelImpl\[/code\] from GWT so results are identical for both anyway. And GWT's documentation says (which Sencha wisely withheld):\[quote\] The back-end server is expected to respond with a content-type of \[code\]'text/html'\[/code\], meaning that the text returned will be treated as HTML. If any other content-type is specified by the server, then the result html sent in the \[code\]onFormSubmit\[/code\] event will be unpredictable across browsers, and the \[code\]FormHandler.onSubmitComplete(FormSubmitCompleteEvent)\[/code\] event may not fire at all.\[/quote\]However, even with sending \[code\]text/html\[/code\] the behaviour is unpredictable across browsers if the payload is XML.Is there a general solution to this? Or am I missing something terribly trivial (I'm looking at GWT for just three days now)?EDIT: I tried prepending \[code\]<html><body>\[/code\] to the file contents so even IE would have a body in the IFrame. Well, it did, but it also resulted in a very, very strange \[code\]innerHTML\[/code\] starting with:\[code\]<?XML:NAMESPACE PREFIX = [default] ...\[/code\]which the XML parser understandably chokes on.
 
Back
Top