Struts中应用showModalDialog(模式窗口)

方案1:
//设定关团窗口的开关
request.setAttribute("close","NO");

通常我们在开发WEB应用时会用到showModalDialog(模式窗口)来增加或修改记录,而应用或设置不当时会造成死循环或页面流转错误,以下对我在Struts上应用showModalDialog(模式窗口)时实现方法描述:
  应用的情况:
  1.在目录树的右键单上选新增,弹出新增窗口--showModalDialog(模式窗口)。
  2.录入数据后submit,调用Action保存数据。
  3.在Action判断保存是否出错,出错时返回新增窗口提示错误,成功后关闭弹出的新窗口并刷新父页面的分类树。

代码简写如下:
目录树页面:

<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");



方案2:

在网页上,我们一般使用window.showModalDialog(<url>,<标题>,<属性>)来弹出一个模态对话框。但是在模态对话框中的提交有时候是无效的,而且页面跳转的话不是在对话框中的。
    解决这个问题的方法一般是在对话框中的页面上添加一个<iframe>,由<iframe>来转发真正的请求。为了增加页面的可重用行,我们一般会增加一个portal页,如下:

<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="you.RequestCacher" %>
<%
    
String requestUrl = "/test/test.do";
    
String params = RequestCacher.getParameters(request);//获取请求参数
    
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跳转的页面如果继续有请求的话,服务器可能服务收到请求(可能是session的问题),还有请求后的跳转页面不会出现在对话框中。

posted on 2009-12-21 13:00 飞熊 阅读(797) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

文章分类

文章档案

收藏夹

搜索

最新评论

阅读排行榜

评论排行榜