深蓝的天空下,有你有我...
共享酸、甜、苦、辣
posts - 23,comments - 19,trackbacks - 0

 

// 设定关团窗口的开关
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 " );
posted on 2006-04-06 16:43 三刀流の逆风 阅读(1465) 评论(0)  编辑  收藏 所属分类: StrutsDHtml

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


网站导航: