dwr实现page分页

(1)在web.xml中配置DWRServlet如下:
   <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>
(2) 在dwr.xml中配置

<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://www.getahead.ltd.uk/dwr//dwr20.dtd">
<dwr>
 <allow>
 
   <!--leadService为Spring 中配置的service 负责取分页数据,返回page对象 --> 
   <create javascript="LeadService" creator="spring">
     <param name="beanName" value="leadService"></param><!--可以采用name="class"  value="com.infowarelab.leadmanagement.service.LeadService"-->
     <include method="listLeadDwr" />    
   </create> 
   <!--返回的page 对象 -->   
   <convert match="org.springside.core.dao.support.Page" converter="bean">
     <param name="include" value="result,totalCount"></param>     
   </convert>
   <!--page对象中List<Lead> reslut -->
   <convert converter="bean" match="com.infowarelab.leadmanagement.model.Lead" >
     <param name="include" value="id,lastName,firstName,company,emailAddress,rank"></param>
   </convert>
   <!-- Lead对象中的LeadRank属性-->
   <convert converter="bean" match="com.infowarelab.leadmanagement.model.LeadRank" >
     <param name="include" value="id,name"></param>
   </convert>  
  <allow>
</dwr>

(3) Page对象 Lead对象

  

(4)页面
<script type='text/javascript' src='${base}/dwr/engine.js'></script> 
<script type='text/javascript' src='${base}/dwr/util.js'></script>
<script type='text/javascript' src='${base}/dwr/interface/LeadService.js'></script>
<script language="javascript">
 function changePage(cPage){
       LeadService.listLeadDwr(cPage,process);
      }
      function process(item){       
       var leads = item.result;       
       DWRUtil.removeAllRows("spanListLeads");
           var cell=[
            function(leads){
              var input = document.createElement("input");
              input.setAttribute("type", "checkbox");
              input.setAttribute("value", leads.id);
         return input;
            },
            function(leads){return leads.lastName+leads.firstName},
            function(leads){return leads.company},
            function(leads){return leads.emailAddress},           
            function(leads){return leads.company},
            function(leads){
             var leadRank = leads.rank;
             if(leadRank!=null)
              return leadRank.name;
             else
              return "";
            }          
           ];
        DWRUtil.addRows("spanListLeads",leads,cell);    
      }

</script>

posted @ 2007-11-22 09:13  eafy.ye  阅读(2516)  评论(1编辑  收藏  举报