作者: ynmc
原文地址:
http://www.blogjava.net/ynmc/archive/2006/06/26/55149.html欢迎转载,请保留出处.
在用DWR传输xml文档(document)或者节点(Element)的时候,通过DWR Debug页面从函数中直接取返回数据时,由于DWR对于Firefox的支持度比IE好的原因,在FireFox下面能正常运行,在IE下会报[Ojbect Error]。我用DWR1.1和DWR M2两个版本都进行了测试,都会报出同样的错误。
关于这个错误,我已经和DWR的作者joe walker通过user-list联系过,他表示由于时间的问题,在ie下面的确有一些bug没有来得及处理。
同时,我又做了一些测试,发现其实这个问题确实如Joe后来回复的邮件所说,是个没有什么意义的小问题。在IE下其实也是可以传递Document或者Element数据的,只是在DWR Debug页面下,直接从函数中返回Document或者Element时,DWR弹出的显示元素的对话框。这个时候DWR隐式的将Document或者Element对象转换成了String,而DWR对FireFox支持的较好,没有问题,而在IE中就会弹出Object Error错误。
所以对实际应用来讲,这个bug完全可以忽略,因为除了debug以外,在使用中没有任何影响。
Joe 最后回复了邮件,也给出了处理办法,他的意思是这种情况出现的比较少,意义不大(我就是听他说了这句话之后发现了开始自己的理解有误,看来多与人交流是非常重要的啊。)
下面是邮件原文:
From: Joe Walker <
joseph.walker@...>
Subject:
Re: Re: [new user]problem: can't send/return DOM object?
Newsgroups:
gmane.comp.java.dwr.user
Date: 2006-06-26 08:32:37 GMT
(1 day and 48 minutes ago)
Expires: This article
expires on 2006-07-10
The DOM converter will convert from browser DOM objects to server
side DOM objects, but it wasn't designed to convert from browser
strings to SS DOM.
How do you parse a browser string into a browser DOM?
This can't be done without some cross-browser tweaks. Take a look at
DWREngine._unserializeDocument(). It is a private method to DWREngine,
so you should not use it directly, but you can copy it.
DWREngine._unserializeDocument = function(xml) {
var dom;
if (window.DOMParser) {
var parser = new DOMParser();
dom = parser.parseFromString(xml, "text/xml");
if (!dom.documentElement || dom.documentElement.tagName == "parsererror") {
var message = dom.documentElement.firstChild.data;
message += "\n" + dom.documentElement.firstChild.nextSibling.firstChild.data;
throw message;
}
return dom;
}
else if (
window.ActiveXObject) {
dom = DWREngine._newActiveXObject(DWREngine._DOMDocument);
dom.loadXML(xml);
// What happens on parse fail with IE?
return dom;
}
else {
var div = document.createElement
('div');
div.innerHTML = xml;
return div;
}
};
There
is bug in IE is that I mentioned in a previous post. The bug is that
HTML nodes do not have the DOM properties to allow DWR to marshall them
properly. This might be something that DWR can work around, but to date
I have never seen the need to fix the bug. Sending the browser HTML DOM
to the server isn't all that useful since the server gave it to the
browser in the first place.
Joe.
目前的ajax框架中DWR的文档是做的比较好的,这也有利于广大的开发者。
DWR 官方站点:
http://getahead.ltd.uk/dwr/
DWR User-list(作者会经常对在这里提出的问题进行回答,目前已经有约5000条记录):
http://news.gmane.org/gmane.comp.java.dwr.user
最后感谢Joe Walker,他不仅写出了DWR,还非常热心的回答了我和其它user的问题。