论坛首页 入门技术论坛

DWR 1.0和3.0,都没问题了!

浏览 1416 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-06-29  

今天在DWR官方网站上链接到javaworld网站上下了一个能动态显示rentInfo信息的war,相信有的朋友已经用过了。我发布到了tomcat上,发现它的dwr是0.9版的,现在dwr都已经是3.0版的了,于是就想把它改写成适合运行在3.0版下。

原1.0怎么的search.jsp,我主要贴script部分:

<script type="text/javascript">
    function updateTotal() {
      $("resultTable").style.display = 'none';
      var bedrooms = document.getElementById("bedrooms").value;
      var bathrooms = document.getElementById("bathrooms").value;
      var price = document.getElementById("price").value;
      ApartmentDAO.countApartments(loadTotal, bedrooms, bathrooms, price);
    };

    function updateResults() {
      DWRUtil.removeAllRows("apartmentsbody");
      var bedrooms = document.getElementById("bedrooms").value;
      var bathrooms = document.getElementById("bathrooms").value;
      var price = document.getElementById("price").value;
      ApartmentDAO.findApartments(fillTable, bedrooms, bathrooms, price);
      $("resultTable").style.display = '';
    };
   
    var getId = function(unit) { return unit.id; };
    var getAddress = function(unit) { return unit.address; };
    var getBedrooms = function(unit) { return unit.bedrooms;};
    var getBathrooms = function(unit) { return unit.bathrooms; };
    var getPrice = function(unit) { return unit.price; };
   
    function loadTotal(data) {
      document.getElementById("totalRecords").innerHTML = data;
    };
   
    function fillTable(apartment) {
     DWRUtil.addRows("apartmentsbody", apartment, [ getId, getAddress, getBedrooms, getBathrooms, getPrice ]);
    };
</script>

 

我修改后的script部分:
<script type="text/javascript">
    function countTotal() {
        $("resultTable").style.display = 'none';
        var bedrooms = document.getElementById("bedrooms").value;
        var bathrooms = document.getElementById("bathrooms").value;
        var price = document.getElementById("price").value;
        ApartmentDAO.countApartments(bedrooms, bathrooms, price,
                function showTotal(data){
                    dwr.util.setValue("totalRecords", data);
        });
    };

    function showResults() {
        var bedrooms = document.getElementById("bedrooms").value;
        var bathrooms = document.getElementById("bathrooms").value;
        var price = document.getElementById("price").value;
        ApartmentDAO.findApartments(bedrooms, bathrooms, price,
            function fillTable(apartment) {
                dwr.util.removeAllRows("apartmentsbody");
                dwr.util.addRows("apartmentsbody", apartment, cellFuncs);
            });
        $("resultTable").style.display = '';
    };

    var cellFuncs = [
        function(data) { return data.id; },
        function(data) { return data.address; },
        function(data) { return data.bedrooms; },
        function(data) { return data.bathrooms; },
        function(data) { return data.price; }
    ];
</script>

 

还有一点要注意的就是html的body部分:

<body onload="countTotal();">

以及在bedrooms、bathrooms和price的下拉框加上onchange="countTotal()",否则不能动态更新。。。

 

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics