谈笑有鸿儒,往来无白丁

在恰当的时间、地点以恰当的方式表达给恰当的人...  阅读的时候请注意分类,佛曰我日里面是谈笑文章,其他是各个分类的文章,积极的热情投入到写博的队伍中来,支持blogjava做大做强!向dudu站长致敬>> > 我的微博敬请收听

                  应用场景,当用户选择一辆车,需要显示这辆车的厂牌型号,如何做dwr来实现一下;

1、dwr.jar 还有bsf.jar 可以在这里下载;(csdn的资源发布了需要等一会才可以看到的)

2、web.xml里面配置一下;

   <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/oaContext.xml</param-value>
    </context-param>
   
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

  <!-- DWR -->
  <servlet>
  <servlet-name>dwr-invoker</servlet-name>
  <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
  <init-param>
    <param-name>debug</param-name>
    <param-value>true</param-value>
  </init-param>
</servlet>
<servlet-mapping>
  <servlet-name>dwr-invoker</servlet-name>
  <url-pattern>/dwr/*</url-pattern>
</servlet-mapping> 

3、写一下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>
  
<!-- init is only needed if you are extending DWR -->
  
<init>
    
<creator id="spring" class="org.directwebremoting.spring.SpringCreator"/>
  
</init>
  
<!-- without allow, DWR isn't allowed to do anything -->
  
<allow>
    
<create creator="spring" javascript="getCarModule">
        
<param name="beanName" value="carService"/>        
    
</create>
    
    
<convert converter="bean" match="com.oa.carmanage.domain.TbCarType">
        
<param name="include" value="carModel"/>
     
</convert>
  
</allow>
  
<!-- you may need to tell DWR about method signatures -->
  
<signatures>
  
</signatures>

</dwr>

 

4、写自己的实现方法注意spring的配置文件需要设置一个bean

 

        <!-- 车辆管理service -->
        
<bean id="carService" class="com.oa.carmanage.car.service.impl.CarServiceImpl">
             
<property name="manager" ref="managerSupport"></property>
        
</bean>

5、里面实现自己的方法

 

    public Object[] getCarModuleByCarNum(String carNum) {    
        List lstret 
= manager.getByQueryName("carmanage.car.service.impl.carservicesimpl.getmodulebycarnum",carNum);     
        
return lstret.toArray();
    }

6、写一个js文件来调用

 

    function getCarModuleByCarNum(){
            
var carNum = $("carNum").value;
            getCarModule.getCarModuleByCarNum(carNum,callback);
        }

        
    
function callback(list){
            
var carModule = $("carModule"); 
            dwr.util.removeAllOptions(carModule);
            
if(list.length==0){
               alert(
"输入有误!");
            }
else{
              dwr.util.addOptions(carModule,list);
            }

        }

7、在jsp文件里面引入js

 

        <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/getCarModule.js'></script>
        
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
        
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script>    
        
<script type="text/javascript" src="<%=request.getContextPath()%>/common/js/getcarmodulebycarnum.js"></script>        

 

8、实现级联动作的代码

 

                                        <tr>
                                            
<td class="td_width110_style">车牌号:</td>
                                       
<td>
                                             
<html:select property="carNum" styleId="carNum" onclick="getCarModuleByCarNum()">                                             
                                                
<html:options collection="carNum" labelProperty="carNum" property="id"/>
                                             
</html:select> 
                                        
</td>
                                        
</tr>
                                        
<tr>
                                            
<td class="td_width110_style">车辆类型:</td>
                                            
<td>
                                               
<select id="carModule"></select>
                                            
</td>
                                        
</tr>    

 

这样就实现了需要的功能!!!good  luck!!!

posted on 2008-08-05 20:35 坏男孩 阅读(1935) 评论(0)  编辑  收藏 所属分类: JAVA名人堂

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


网站导航: