// 設定關團窗口的開關
request.setAttribute( " close " , " NO " );
通常我們在開發WEB應用時會用到showModalDialog(模式窗口)來增加或修改記錄,而應用或設置不當時會造成死循環或頁面流轉錯誤,以下對我在Struts上應用showModalDialog(模式窗口)時實現方法描述:
應用的情況:
1.在目錄樹的右鍵單上選新增,彈出新增窗口--showModalDialog(模式窗口)。
2.錄入數據后submit,調用Action保存數據。
3.在Action判斷保存是否出錯,出錯時返回新增窗口提示錯誤,成功后關閉彈出的新窗口并刷新父頁面的分類樹。
代碼簡寫如下:
目錄樹頁面:
< A HREF ="javascript: addTree();" > 新增節點 </ A >
< SCRIPT language ='JavaScript' type ='text/javascript' >
function addTree(){
// 用于準備新增頁面所需的元素準備
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中判斷新增是否成功,成功則:
// 設定關團窗口的開關
request.setAttribute( " close " , " OK " );
否則:
// 設定關團窗口的開關
request.setAttribute( " close " , " NO " );
posted on 2006-04-06 16:43
三刀流の逆風 閱讀(1476)
評論(0) 編輯 收藏 所屬分類:
Struts 、
DHtml