论坛首页 入门技术论坛

dwr 无法converter javabean 提示no converter found for

浏览 11042 次
该帖已经被评为新手帖
作者 正文
   发表时间:2008-03-30  
DWR
程序可以运行,但无法取到javabean的数据,ie7打开弹出对话框:‘name’(name为javabean一个属性)为空或不是对象 ,firefox提示“item has no perpertise”  ,我用的dwr版本是 2.02 ,其他也试过了一样的问题 ,搞了好久,实在找不出原因啊 ,哪位大哥帮忙看看啊
tomcat 打印如下信息:
2008-03-30 21:49:22,281 [org.directwebremoting.dwrp.DefaultConverterManager]-[ERROR] No converter found for 'org.zm.dwr.Item'
[org.directwebremoting.dwrp.DefaultConverterManager]-[ERROR] No converter found for 'org.zm.dwr.Item'
2008-03-30 21:49:22,296 [org.directwebremoting.dwrp.DefaultConverterManager]-[ERROR] No converter found for 'org.zm.dwr.Item'

--我的jsp和javascript文件
<script type="text/javascript"
			src="/DwrTest/dwr/interface/shopping.js"></script>
		<script type="text/javascript" src="/DwrTest/dwr/engine.js"></script>
		<script type="text/javascript" src="/DwrTest/dwr/util.js"></script>
		<script type="text/javascript">
    window.onload = function(){
      shopping.getList(displayItems);
    
    }
    function displayItems(items){
      DWRUtil.removeAllRows("content") ;  //先移除table数据
      if(items.length!=0){alert(items.length);} //运行时 提示长度为 3
      DWRUtil.addRows("content",items,cellFunctions); //填充table
    }
 var cellFunctions=[
       function(item){ return item.name;},
       function(Item){ return item.description;},
       function(item){ return item.price;},
       function(item){
        var btn = document.createElement("button");
        btn.innerHtml="add" ;
        return btn ;
 }
    </script>
	</head>
	<body>
		<table>
			<tbody id="content">
				<!-- 在此填充数据 --> </tbody>
		</table>
	</body>

---DBFactory 类 :我的数据工厂类package org.zm.dwr;
import java.util.HashMap;
import java.util.Map;
public class DBFactory {
	private static Map<String ,Item> allItems= new HashMap<String,Item>() ;
	static{
		    allItems.put("1111", new Item("aaaaa","bbbbbb","ccccc",1999));
		    allItems.put("2222", new Item("acdfdf","sdfsdf","sdaffsdaf",1129));
		    allItems.put("33333", new Item("234dsd","vsadsdf","234sdsdf",1542));
	}
	public static Map getAllItems(){
		return allItems ;
	}
}


---DAO类
package org.zm.dwr;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ShoppingDAO extends DBFactory {
	@SuppressWarnings("unchecked")
	public List getList(){
		ArrayList<Item> list = new ArrayList<Item>() ;
		Iterator<Item> i = getAllItems().values().iterator();
		while(i.hasNext()){
			Item item = i.next() ;
			list.add(item);
			System.out.println(item.getName());
		}
		return list ;
	}
}

----javabean
package org.zm.dwr;
public class Item{
	  private String id;
	  private String name;
	  private String description;
	  private int price;
	  public Item(String id, String name, String description, int price) {
		    this.id = id;
		    this.name = name;
		    this.description = description;
		    this.price = price;
		  }
	  public String getDescription() {
		return description;
	}
	public String getId() {
		return id;
	}
	public String getName() {
		return name;
	}
	public int getPrice() {
		return price;
	}
}

--我的dwr.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
    "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
    "http://getahead.org/dwr/dwr20.dtd">
<dwr>
  <allow>
    <create javascript="shopping" creator="new" scope="session">
    <param name="class" value="org.zm.dwr.ShoppingDAO"></param>
    <include method="getList"/>
    </create>
   <convert match="bean" converter="org.zm.dwr.Item"></convert></allow>
</dwr>
   发表时间:2008-04-02  
There is no converter for your class org.zm.dwr.Item
Pls read the doc about dwr.xml
0 请登录后投票
   发表时间:2008-05-25  
javabean 没有setter方法,光有getter方法。我是这么认为的,不知道对不对
0 请登录后投票
   发表时间:2008-05-25  
dwr会害死人的
0 请登录后投票
   发表时间:2008-05-27  
<convert match="bean" converter="org.zm.dwr.Item"></convert></allow>
写错了,应该是<convert  converter="bean" match="org.zm.dwr.Item"></convert></allow>
1 请登录后投票
   发表时间:2008-06-02  
同样的问题,郁闷,找原因不到
0 请登录后投票
   发表时间:2008-06-26  
我也遇到同样的问题啊,用dwr/debug得到的结果是[null,null]?
1 请登录后投票
论坛首页 入门技术版

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