Struts中應(yīng)用showModalDialog(模式窗口)

          方案1:
          //設(shè)定關(guān)團(tuán)窗口的開關(guān)
          request.setAttribute("close","NO");

          通常我們在開發(fā)WEB應(yīng)用時會用到showModalDialog(模式窗口)來增加或修改記錄,而應(yīng)用或設(shè)置不當(dāng)時會造成死循環(huán)或頁面流轉(zhuǎn)錯誤,以下對我在Struts上應(yīng)用showModalDialog(模式窗口)時實(shí)現(xiàn)方法描述:
            應(yīng)用的情況:
            1.在目錄樹的右鍵單上選新增,彈出新增窗口--showModalDialog(模式窗口)。
            2.錄入數(shù)據(jù)后submit,調(diào)用Action保存數(shù)據(jù)。
            3.在Action判斷保存是否出錯,出錯時返回新增窗口提示錯誤,成功后關(guān)閉彈出的新窗口并刷新父頁面的分類樹。

          代碼簡寫如下:
          目錄樹頁面:

          <A?HREF="javascript:?addTree();">新增節(jié)點(diǎn)</A>
          <SCRIPT?language='JavaScript'?type='text/javascript'>
          ?
          function?addTree(){
          ??
          //用于準(zhǔn)備新增頁面所需的元素準(zhǔn)備
          ??var?URL=?"treeAction.do?method=add&parentid=";??
          ??
          if?(d.getSelected()==null?){
          ???URL?
          =?URL?+?'0';
          ??}
          else{
          ???URL?
          =?URL?+?tree.getSelected();
          ??}
          ??
          //alert(URL);
          ??window.showModalDialog(URL,window,"center:true;");
          ?} 
          </SCRIPT>

          新增頁面--showModalDialog(模式窗口):

          <%@?include?file="/include/jsp/taglib.jsp"?%>

          <!--?save?ok!?LiuYX-->
          <logic:equal?name="close"?value="OK">
          ??????
          <script?language="javascript">
          ??????
          <!--
          ??????????
          //alert("here");
          ??????????var?parentWindow?=?window.dialogArguments;??????????
          ??????????parentWindow.location.reload();
          ????????window.close();
          ????
          //?-->
          ????</script>????
          </logic:equal>??????
          ??????
          <!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN">
          <html:html?lang="true">
          ??
          <head>
          ????
          <html:base?target="_self"/>
          ????
          <title>Add?Form</title>
          ????
          <meta?http-equiv="pragma"?content="no-cache">
          ????
          <meta?http-equiv="cache-control"?content="no-cache">
          ????
          <meta?http-equiv="expires"?content="0">????
          ????
          <meta?http-equiv="description"?content="cate?edit">
          ????
          ??
          </head>
          ??
          ??
          <body>?
          ??
          <html:errors/>?????
          ??
          <!--?add?begin?-->??
          ???
          <html:form?action="/treeAction.do?method=update"?method="post">
          ????
          <html:hidden?property="parentid"/>
          ??????
          <table?border="0"??align="center">
          ????????
          <tr>
          ??????????
          <td><bean:message?bundle="ar1"?key="catename"/>:</td>
          ??????????
          <td>
          ????????????
          <html:text?property="catename"/>
          ????????????????????
          ??????????
          </td>
          ????????
          </tr>
          ????????
          <tr></tr>
          ????????
          <tr>
          ??????????
          <td?align="center"><html:submit><bean:message?bundle="ar1"?key="button.save"/></html:submit></td>
          ??????????
          <td?align="center"><html:button?property="button"?onclick="javascript:window.close();"><bean:message?bundle="ar1"?key="button.cancel"/></html:button></td>
          ????????
          </tr>
          ??????
          </table>
          ????
          </html:form>
          ??
          </body>
          </html:html>

          最后在Action中判斷新增是否成功,成功則:

          //設(shè)定關(guān)團(tuán)窗口的開關(guān)
          request.setAttribute("close","OK");

          否則:

          //設(shè)定關(guān)團(tuán)窗口的開關(guān)
          request.setAttribute("close","NO");



          方案2:

          在網(wǎng)頁上,我們一般使用window.showModalDialog(<url>,<標(biāo)題>,<屬性>)來彈出一個模態(tài)對話框。但是在模態(tài)對話框中的提交有時候是無效的,而且頁面跳轉(zhuǎn)的話不是在對話框中的。
          ??? 解決這個問題的方法一般是在對話框中的頁面上添加一個<iframe>,由<iframe>來轉(zhuǎn)發(fā)真正的請求。為了增加頁面的可重用行,我們一般會增加一個portal頁,如下:

          <%@?page?contentType="text/html;?charset=gb2312"?%>
          <%@?page?import="you.RequestCacher"?%>
          <%
          ????
          String?requestUrl?=?"/test/test.do";
          ????
          String?params?=?RequestCacher.getParameters(request);//獲取請求參數(shù)
          ????
          String?action?=?requestUrl+"?"+params;
          %>

          <table?width="100%"?height="100%"?border="0"?cellspacing="0">
          ????
          <tr>
          ????????
          <td>
          ????????????
          <iframe?width="100%"?height="100%"?src="<%=action%>"></iframe>
          ????????
          </td>
          ????
          </tr>
          </table>
          ??
          ?? 下面說明一下如上代碼。一般我們可能會在彈出對話框時使用這樣的方式:window.showModalDialog("/test/test.do",“測試”,"dialogWidth:500px;dialogheight:650px"),如果這樣的話,test.do跳轉(zhuǎn)的頁面如果繼續(xù)有請求的話,服務(wù)器可能服務(wù)收到請求(可能是session的問題),還有請求后的跳轉(zhuǎn)頁面不會出現(xiàn)在對話框中。

          posted on 2009-12-21 13:00 飛熊 閱讀(822) 評論(0)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 涞源县| 久治县| 荆门市| 金秀| 克拉玛依市| 蕲春县| 西吉县| 丰宁| 临安市| 新密市| 丰城市| 金乡县| 邹平县| 平远县| 浦城县| 三门县| 平谷区| 康马县| 托克托县| 麻阳| 东源县| 桐乡市| 平谷区| 梓潼县| 清水河县| 黎川县| 房产| 顺昌县| 平安县| 漠河县| 大关县| 北票市| 长葛市| 民和| 内乡县| 盐源县| 子长县| 历史| 峨边| 墨玉县| 梧州市|