談笑有鴻儒,往來無白丁

          在恰當的時間、地點以恰當的方式表達給恰當的人...  閱讀的時候請注意分類,佛曰我日里面是談笑文章,其他是各個分類的文章,積極的熱情投入到寫博的隊伍中來,支持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 壞男孩 閱讀(2042) 評論(0)  編輯  收藏 所屬分類: JAVA名人堂
          主站蜘蛛池模板: 潢川县| 库尔勒市| 大理市| 北川| 光泽县| 肇庆市| 贵定县| 当雄县| 永兴县| 汤阴县| 凤台县| 平舆县| 金乡县| 胶南市| 车险| 麦盖提县| 宁强县| 来安县| 平利县| 东明县| 阿荣旗| 建水县| 松原市| 黄陵县| 临江市| 栾川县| 定结县| 紫云| 原平市| 乌兰浩特市| 绥滨县| 卫辉市| 定安县| 资阳市| 原平市| 金塔县| 普兰县| 桐柏县| 白银市| 布拖县| 林州市|