①、在正常配置DWR(包括reverse ajax配置)及JSF之后在web.xml中做如下定義: ? ???? < filter > ???????? < filter-name > DwrFacesFilter </ filter-name > ???????? < filter-class > ????????????org.directwebremoting.faces.FacesExtensionFilter ???????? </ filter-class > ???? </ filter > ???? < filter-mapping > ???????? < filter-name > DwrFacesFilter </ filter-name > ???????? < url-pattern > /dwr/* </ url-pattern > ???? </ filter-mapping > ? ②、在jsp頁面中,引入DWR的一些js腳本,并編寫你自己的javascript,例如: ?? < script?type = ' text/javascript ' ?src = ' /DWRTest/dwr/engine.js ' > ? </ script > ?? < script?type = ' text/javascript ' ?src = ' /DWRTest/dwr/util.js ' > ? </ script > ?? < script > ?? function ?alertTest(msg) ... { ???alert(msg); ??} ?? </ script > ? 在<body>標(biāo)簽中增加一個(gè)reverse ajax的顯式設(shè)置:<body onload="dwr.engine.setActiveReverseAjax(true);"> ③、ManagedBean中,寫一個(gè)actionListener方法 ?FacesContext?facesContext? = ?FacesContext.getCurrentInstance(); ?ServletContext?servletContext? = ?(ServletContext)facesContext.getExternalContext().getContext(); ?ServerContext?sctx? = ?ServerContextFactory.get(servletContext); Collection?sessions? = ?sctx.getScriptSessionsByPage( " /DWRTest/test.faces " ); Util?pages? = ? new ?Util(sessions); pages.addFunctionCall( " alertTest " ,? " hello?dwr " ); ? 注意,不能采用DWR在普通jsp中獲取ServletContext的方法,因?yàn)樵谀欠N方式中,URL的解析是通過DWRServlet解析的,而在JSF中是由FacesServlet來解析的,所以使用WebContextFactory.get().getServletContext() 會得到NullPointerException. 此處不用在dwr.xml中定義相應(yīng)的內(nèi)容,因?yàn)榭蛻舳瞬恍枰{(diào)用服務(wù)器端,而是服務(wù)器端調(diào)用客戶端。? JSF與DWR的整合 更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主 微信掃碼或搜索:z360901061 微信掃一掃加我為好友 QQ號聯(lián)系: 360901061 您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。 【本文對您有幫助就好】元 2元 5元 10元 20元 自定義 喜歡作者