您的位置:首页 > 其它

DWR传递对象的一些经验

2006-11-02 08:24 183 查看
DWR.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://www.getahead.ltd.uk/dwr/dwr20.dtd">
<dwr>
<allow>
<convert converter="bean" match="com.boco.webmaster.ajax.dto.*"/>
<convert converter="bean" match="com.boco.webmaster.ajax.common.ui.*"/>
<convert converter="bean" match="com.boco.transnms.common.dto.*"/>

<create creator="new" javascript="CommonAjaxAction" scope="application">
<param name="class" value="com.boco.webmaster.ajax.action.CommonAjaxAction"/>
</create>

</allow>
<signatures>
<![CDATA[
import java.util.*;
import dwr.sample.*;
CommonAjaxAction.addList(List<TopoLink>);
CommonAjaxAction.addMap(Map<TopoLink>);
]]>
</signatures>
</dwr>

1.jsp

<script src='/webmaster/dwr/interface/CommonAjaxAction.js'></script>
<script src='/webmaster/dwr/engine.js'></script>
<script src='/webmaster/dwr/util.js'></script>
<script src='/webmaster/common/js/utility/DwrAjaxHelper.js'></script>
<script type="text/javascript">
function aa(){
var a = channelForm.rate.value;
var b = channelForm.relatedTransSystem.value;
var arrayName=new Array(a,b);
//alert(arrayName[0]);
//var params = DWRUtil.getValues(user);
CommonAjaxAction.addList(arrayName,function(data){
// parseList(data);
});
}
function bb(){
var a = channelForm.rate.value;
var b = channelForm.relatedTransSystem.value;
var depts={"rate":a,"relatedTransSystem":b};
CommonAjaxAction.addMap(depts,function(data){
alert(data);
var mp = DWRUtil.getValues(data);
alert(mp.rate);
});
}
</script>
<!--脚本代码区域结束-->
<wmtag:head title="PDH通道管理"/>
<body class="clssclbar">
<center>
<html:form action="/channel/makeChannel.do">
<table cellspacing="0" bordercolordark="#ffffff" cellpadding="0" width="80%" bordercolorlight="#808080" border="1" bgcolor="#f5f5f5" align="center">
<tr>
<td colspan="8" align="center" valign="top" class="clsscd">PDH通道管理</td>
</tr>
<tr>
<td width="50%" class="clsthl" colspan="3">通道速率
<html:text property="rate" style="width:70%"></html:text> 

</td>
<td width="50%" class="clsthl" colspan="3">所属传输系统
<html:text property="relatedTransSystem" style="width:70%"></html:text> 

</td>
</tr>

<tr>
<td class="clsthl" colspan="6">
<div align="right">
<button type="button" onclick="aa()">生成通道</button>
<input type="BUTTON" value="查看源代码" onClick='window.location = "view-source:" + window.location.href' name="BUTTON">
</div>
</td>
</tr>
</table>
</html:form>
</center>
</body>
</html>

CommonAjaxAction:

public List addList(HttpServletRequest request,List topoLinkList){
List elementList = new ArrayList();
if(topoLinkList.size()>0 && topoLinkList!=null){
for(int i = 0; i < topoLinkList.size(); i++){
String elements = (String)topoLinkList.get(i);
elementList.add(elements);
}
}
return elementList;
}

public Map addMap(HttpServletRequest request,Map topoLinkMap){
Map a = new HashMap();
if(topoLinkMap.size()>0 && topoLinkMap!=null){
java.util.Iterator miter = topoLinkMap.keySet().iterator();
while(miter.hasNext()){
String mkey = (String)miter.next();
String mvalue = (String)topoLinkMap.get(mkey);
a.put(mkey,mvalue);
}
}
return a;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: