0

zk5.0.2中基于注解对象图浏览的bug

asked 2010-06-11 00:11:36 +0800

SummerGreen2008 gravatar image SummerGreen2008
30

zk5.0中基于注解对象图浏览的bug

举例:列出用户所在部门的所有员工

<listbox model="@{indexWin.user.dept.users}">
<listitem self="@{each=user}" label="@{user.name}"
</listbox>

这里代码是没有任何问题的

但是如果开发人员在Dept类中未提供users的get方法,问题就出来了

1,在zk3.6.4中报错如下:



org.zkoss.zk.ui.UiException: java.lang.NoSuchMethodException: class com.xxxxx.xxxxx.web.zk.controller.IndexController: name=users args=null
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
org.zkoss.lang.Classes.newInstance(Classes.java:78)
........................................................................



2,但是在zk.5.xxx.xxx报错如下:


org.zkoss.zk.ui.UiException: Expects java.util.Set, java.util.List, java.util.Map, Object[], Enum Class, or BindingListModel only. class com.xxxxx.xxxxx.web.zk.controller.IndexController
org.zkoss.zkplus.databind.ListModelConverter.coerceToUi(ListModelConverter.java:57)
org.zkoss.zkplus.databind.Binding.myLoadAttribute(Binding.java:366)
org.zkoss.zkplus.databind.Binding.loadAttribute(Binding.java:336)
org.zkoss.zkplus.databind.DataBinder.loadAttrs(DataBinder.java:572)


zk3.6.4的异常时正确的,因为由于开发人员的疏忽,忘记写getUsers方法,报 java.lang.NoSuchMethodException异常正确反映了当前错误


但是zk.5.xx.xx呢,

报道异常却是org.zkoss.zk.ui.UiException: Expects java.util.Set, java.util.List, java.util.Map, Object[], Enum Class, or BindingListModel only

下面重点讲述一下为什么?


首先看一下<listbox model="@{indexWin.user.dept.users}">
<listitem self="@{each=user}" label="@{user.name}"
</listbox>


在zk3.6.4中,它是这么解析的:首先找到indexWin组件,再从indexWin组件内查找getUser方法


然后从返回的user对象中,找getDept方法,最后从dept对象中查找getUsers方法


在查找的过程中,如果未找到,立即报错,报无匹配get方法错误




在zk5.xxx.xxx中,首先找到indexWin组件,再从indexWin组件内查找getUser方法


然后从返回的user对象中,找getDept方法,最后从dept对象中查找getUsers方法


但与3.6.4不同的是:在查找的过程中,如果未找到get方法,zk5则返回上一个找到的对象

举个例子:
1,如在dept类中未提供getUsers方法,@{indexWin.user.dept.users}返回dept对象
2,如在user类中未提供getDept方法,@{indexWin.user.dept.users}返回user对象
3,如在indexWin类中未提供getUser方法,@{indexWin.user.dept.users}返回indexWin对象



再回过头来,看开始部分举得例子
<listbox model="@{indexWin.user.dept.users}">

<listitem self="@{each=user}" label="@{user.name}"
</listbox>


由于未提供getUsers方法,@{indexWin.user.dept.users}返回的结果为dept对象,但是listbox model属性接受的类型仅为 java.util.Set, java.util.List, java.util.Map, Object[], Enum Class, or BindingListModel ,因此在类型转换的时候报错

delete flag offensive retag edit
Be the first one to reply this discussion!
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-06-11 00:11:36 +0800

Seen: 847 times

Last updated: Jun 11 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More