天山?jīng)隹?/a>

          java分壇

          DWR 用xom,dom4j傳輸Document或者Element數(shù)據(jù)的小問題。

          作者: ynmc
          原文地址:http://www.aygfsteel.com/ynmc/archive/2006/06/26/55149.html歡迎轉(zhuǎn)載,請(qǐng)保留出處.

          在用DWR傳輸xml文檔(document)或者節(jié)點(diǎn)(Element)的時(shí)候,通過DWR Debug頁面從函數(shù)中直接取返回?cái)?shù)據(jù)時(shí),由于DWR對(duì)于Firefox的支持度比IE好的原因,在FireFox下面能正常運(yùn)行,在IE下會(huì)報(bào)[Ojbect Error]。我用DWR1.1和DWR M2兩個(gè)版本都進(jìn)行了測(cè)試,都會(huì)報(bào)出同樣的錯(cuò)誤。

          關(guān)于這個(gè)錯(cuò)誤,我已經(jīng)和DWR的作者joe walker通過user-list聯(lián)系過,他表示由于時(shí)間的問題,在ie下面的確有一些bug沒有來得及處理。

          同時(shí),我又做了一些測(cè)試,發(fā)現(xiàn)其實(shí)這個(gè)問題確實(shí)如Joe后來回復(fù)的郵件所說,是個(gè)沒有什么意義的小問題。在IE下其實(shí)也是可以傳遞Document或者Element數(shù)據(jù)的,只是在DWR Debug頁面下,直接從函數(shù)中返回Document或者Element時(shí),DWR彈出的顯示元素的對(duì)話框。這個(gè)時(shí)候DWR隱式的將Document或者Element對(duì)象轉(zhuǎn)換成了String,而DWR對(duì)FireFox支持的較好,沒有問題,而在IE中就會(huì)彈出Object Error錯(cuò)誤。

          所以對(duì)實(shí)際應(yīng)用來講,這個(gè)bug完全可以忽略,因?yàn)槌薲ebug以外,在使用中沒有任何影響。

          Joe 最后回復(fù)了郵件,也給出了處理辦法,他的意思是這種情況出現(xiàn)的比較少,意義不大(我就是聽他說了這句話之后發(fā)現(xiàn)了開始自己的理解有誤,看來多與人交流是非常重要的啊。)

          下面是郵件原文:

          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的文檔是做的比較好的,這也有利于廣大的開發(fā)者。
          DWR 官方站點(diǎn):
          http://getahead.ltd.uk/dwr/

          DWR User-list(作者會(huì)經(jīng)常對(duì)在這里提出的問題進(jìn)行回答,目前已經(jīng)有約5000條記錄):
          http://news.gmane.org/gmane.comp.java.dwr.user

          最后感謝Joe Walker,他不僅寫出了DWR,還非常熱心的回答了我和其它user的問題。

          posted on 2006-06-26 14:27 Ynmc 閱讀(2325) 評(píng)論(3)  編輯  收藏 所屬分類: Ajax

          評(píng)論

          # re: DWR 用xom,dom4j傳輸xml數(shù)據(jù)的Bug。 2006-06-26 16:13 charon@xxx

          其實(shí)如果要用到xml的話,不必使用dwr的。不過dwr確實(shí)是個(gè)好東西。  回復(fù)  更多評(píng)論   

          # re: DWR 用xom,dom4j傳輸xml數(shù)據(jù)的Bug。 2006-06-27 08:37 我心飛翔

          我剛接觸ajax,日后還得多請(qǐng)教你。  回復(fù)  更多評(píng)論   

          # re: DWR 用xom,dom4j傳輸xml數(shù)據(jù)的Bug。 2006-06-27 17:00 Ynmc

          其實(shí)xml只是為傳輸數(shù)據(jù)定義格式,我們做web應(yīng)用的時(shí)候,主要是看中它對(duì)httpservlet的封裝和前臺(tái)代碼的簡化,另外dwr提供的DWRUtil.js功能也不錯(cuò).
          不過charon說的的確沒有,如果自己寫一點(diǎn)servlet再加上xml傳輸,是可以丟掉dwr的,這樣還精簡一些.

          to 我心飛翔:
          大家一起交流,我也是newbie,菜菜仔一個(gè).  回復(fù)  更多評(píng)論   


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2006年6月>
          28293031123
          45678910
          11121314151617
          18192021222324
          2526272829301
          2345678

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(1)

          我參與的團(tuán)隊(duì)

          隨筆分類

          隨筆檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 北海市| 含山县| 肇东市| 金寨县| 江油市| 东莞市| 饶河县| 原阳县| 信宜市| 盐亭县| 青田县| 淮北市| 敦化市| 万源市| 曲水县| 荆州市| 晋城| 苗栗县| 微山县| 旌德县| 延寿县| 景洪市| 舒兰市| 皋兰县| 莱阳市| 西安市| 玛多县| 丹东市| 龙泉市| 西华县| 万州区| 共和县| 当雄县| 华宁县| 璧山县| 乐业县| 丰城市| 保定市| 武清区| 天等县| 兰溪市|