dwr 级联菜单实现

直入主题:

 

dwr配置文件:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">

<dwr>
    <allow>
        <create javascript="readVideoType" creator="spring">      
            <param name="beanName" value="readVideoType"></param>           
       </create>
	   <convert converter="bean" match="com.video.entity.VideoType"/>
	   <convert converter="bean" match="com.video.entity.SubType"/>
    </allow>
</dwr>

 

web.xml配置文件不在说了,到处都是.

 

spring配置文件

<bean id="readVideoType"
 class="com.video.dwr.ReadVideoTypeDWR">
                <property name="videoTypeDAO">
		<ref bean="videoTypeDAO"/>
	</property>
	<property name="subTypeDAO">
		<ref bean="subTypeDAO"/>
	</property>	
</bean>

 

 

dwr实现类:

 

package com.video.dwr;

import java.util.List;

import com.video.dao.ISubTypeDAO;
import com.video.dao.IVideoTypeDAO;
import com.video.entity.SubType;
import com.video.entity.VideoType;

public class ReadVideoTypeDWR {
	private IVideoTypeDAO videoTypeDAO;
	private ISubTypeDAO subTypeDAO;
	public void setSubTypeDAO(ISubTypeDAO subTypeDAO) {
		this.subTypeDAO = subTypeDAO;
	}
	public void setVideoTypeDAO(IVideoTypeDAO videoTypeDAO) {
		this.videoTypeDAO = videoTypeDAO;
	}
	public List<VideoType> getVideoTypes(){
		return videoTypeDAO.getVideoTypeByName("");
	}
	
	public List<SubType> getSubTypesByVideoTypeId(int videoTypeId){
		return subTypeDAO.getSubTypeByVideoType(videoTypeId, "");
	}
}

 

jsp主要代码:

<script type='text/javascript' src='./dwr/engine.js'></script>
<script type='text/javascript' src='./dwr/util.js'></script>
<script type='text/javascript' src='./dwr/interface/readVideoType.js'></script>
<script language="javascript" type="text/javascript">
function getPlanItem(){
    readVideoType.getVideoTypes(callBack);
}
function callBack(lst){
	if (typeof window['DWRUtil'] == 'undefined') 
    window.DWRUtil = dwr.util; 
    DWRUtil.removeAllOptions("videoType");
    DWRUtil.addOptions("videoType", lst, 'videoTypeId', 'videoTypeName');

}
function getSubType(){
	readVideoType.getSubTypesByVideoTypeId(DWRUtil.getValue("videoType"),callBack1);
}
function callBack1(lst){
	 DWRUtil.removeAllOptions("subType");
    DWRUtil.addOptions("subType", lst, 'subTypeId', 'subTypeName');
}
</script>
</head>
<body onload="getPlanItem();">
<select name="videoType" id="videoType" size="1" onchange="getSubType();"></select>
<select name="subType" id="subType" size="1" ></select>
</body>
</html>

 

 

 

这样就可以用dwr实现级联菜单了o(∩_∩)o

你可能感兴趣的:(JavaScript,DAO,spring,bean,DWR)