论坛首页 入门技术论坛

请问这个demo有什么问题

浏览 1391 次
该帖已经被评为新手帖
作者 正文
   发表时间:2008-01-24  
DWR
我的测试运行环境是eclipse3.2,用内建的tomcat作为服务器,测试下来,当我按第一次时,并不会显示一条记录,按多次后也是有几次不出现然后集中在一起出现好几条记录,然后还会出现concurrentmodificationexception异常,请问问题在哪?感觉那个同步有问题.

package org.chaos.dwr;

import java.util.ArrayList;

import java.util.List;



public class UserManager {

    private List<User> users = new ArrayList<User>();

   

    public void add(final User user){

       synchronized(this){

           users.add(user);

       }

    }

   

    public List<User> getAll(){

       synchronized(this){

           return users;

       }

    }

}



public class User {

 
    private String id;

    private String name;

    private String title;

  
  
 
    public String getName() {

       return name;

    }

    public void setName(String name) {

       this.name = name;

    }

 
      

    public String getId() {

       return id;

    }

    public void setId(String id) {

       this.id = id;

    }

    public String getTitle() {

       return title;

    }

    public void setTitle(String title) {

       this.title = title;

    }
}



<?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>  
    <allow>         
       <create javascript="jsmanager" creator="new" scope="application">  

            <param name="class" value="org.chaos.dwr.UserManager"></param>  

        </create>

       <convert match="org.chaos.dwr.User" converter="bean"></convert>

    </allow>  
</dwr> 



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

<html>

<head>

<style>

.usersTable {

    background: #FFFFFF;

    border-collapse: collapse;

}



.usersTable th {

    background: #DDDDDD;

    border: 1px solid #FFFFFF;

}



.usersTable td {

    border: 1px solid #FFFFFF;

}



.usersTable tr {

    background: #FFBBBB;

    border: 1px solid #FFFFFF;

}



</style>

<script type='text/javascript' src='/DWR2.0/dwr/interface/jsmanager.js'></script>

<script type='text/javascript' src='/DWR2.0/dwr/engine.js'></script>

<script type='text/javascript' src='/DWR2.0/dwr/util.js'></script>

<script type='text/javascript'>

window.onload = function() {

    jsmanager.getAll(fillTable);

}



function addUser() {

    var user = { id:"", name:"", title:"" };

    DWRUtil.getValues(user);

    jsmanager.add(user);

    jsmanager.getAll(fillTable);

}



var cellFuncs = [

  function(data) { return data.id; },

  function(data) { return data.name; },

  function(data) { return data.title; }

];



function fillTable(users) {

    DWRUtil.removeAllRows("usersBody");

    DWRUtil.addRows("usersBody", users, cellFuncs);

}

</script>



</head>



<body>

<h3>Edit User</h3>

<table class="usersTable">

    <thead>

       <tr>

           <th>id</th>

           <th>Name</th>

           <th>Title</th>

       </tr>

    </thead>

    <tbody id="usersBody" />

</table>



<br />



<table>

    <tbody>

       <tr>

           <td>Id:</td>

           <td><input id="id" type="text" size="30" /></td>

       </tr>

       <tr>

           <td>Name:</td>

           <td><input id="name" type="text" size="30" /></td>

       </tr>

       <tr>

           <td>Title:</td>

           <td><input id="title" type="text" size="30" /></td>

       </tr>

       <tr>

           <td><input type="button" value="add" onclick="addUser()" /></td>

       </tr>

    </tbody>

</table>



</body>

</html>
   发表时间:2008-01-25  
没人回答吗? 哪位大侠看看. 谢了.
0 请登录后投票
   发表时间:2008-01-30  
这么久还没人回.
0 请登录后投票
论坛首页 入门技术版

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