PropertyModel 表达式的异常:org.apache.wicket.WicketRuntimeException:没有为类定义 get 方法:
我使用 PropertyModel
作为我的 DropDownChoice
的一部分,如下所示:
List<String> choices = Arrays.asList(new String[] { "Library", "School Office", "Science Dept" });
String selected = "Library";
DropDownChoice<String> serviceDDC =
new DropDownChoice<String>("service", new PropertyModel(this, "choices.0"), choices);
不知何故,我遇到了这个异常:
caused by: org.apache.wicket.WicketRuntimeException: No get method defined for class: class com.samoo.tool.pages.CreatePrintingJob expression: choices
at org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:481)
at org.apache.wicket.util.lang.PropertyResolver.getObjectAndGetSetter(PropertyResolver.java:332)
at org.apache.wicket.util.lang.PropertyResolver.getObjectAndGetSetter(PropertyResolver.java:242)
at org.apache.wicket.util.lang.PropertyResolver.getValue(PropertyResolver.java:95)
at org.apache.wicket.model.AbstractPropertyModel.getObject(AbstractPropertyModel.java:130)
at org.apache.wicket.Component.getDefaultModelObject(Component.java:1724)
....
我知道表达式有问题。我一直在尝试不同的参数输入,但它仍然不起作用。有人可以帮忙吗?
I used PropertyModel
as the part of my DropDownChoice
as following:
List<String> choices = Arrays.asList(new String[] { "Library", "School Office", "Science Dept" });
String selected = "Library";
DropDownChoice<String> serviceDDC =
new DropDownChoice<String>("service", new PropertyModel(this, "choices.0"), choices);
Somehow I've got this exception thown:
caused by: org.apache.wicket.WicketRuntimeException: No get method defined for class: class com.samoo.tool.pages.CreatePrintingJob expression: choices
at org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:481)
at org.apache.wicket.util.lang.PropertyResolver.getObjectAndGetSetter(PropertyResolver.java:332)
at org.apache.wicket.util.lang.PropertyResolver.getObjectAndGetSetter(PropertyResolver.java:242)
at org.apache.wicket.util.lang.PropertyResolver.getValue(PropertyResolver.java:95)
at org.apache.wicket.model.AbstractPropertyModel.getObject(AbstractPropertyModel.java:130)
at org.apache.wicket.Component.getDefaultModelObject(Component.java:1724)
....
I know that there's something wrong with the expression. I've been trying different parameter inputs but it still doesn't work. Could anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于您使用的是
PropertyModel(this, "choices.0")
,Wicket 尝试通过getChoices() 方法通过反射查找名为
。正如异常所示,此方法似乎不存在于 com.samoo.tool.pages.CreatePrintingJob 中。choices
的属性声明 PropertyModel 的类的另外,如果
0
是索引,您应该使用[index]
表达式访问它,正如此 JIRA 问题所示:PropertyModel 不支持仅索引属性 ("[0]")但是,您似乎想要初始化
DropDownChoice
到choices
的第一个元素。但是,如果您将 DropDownChoice 的模型设置为PropertyModel(this, "choices.[0"])
,Wicket 将按以下方式映射此 DropDownChoice 的选择:choices
列表中的第一个元素。choices
列表的第一个位置。总而言之,表示
DropDownChoice
选择的支持对象将是choices
列表中的第一个元素。因此,您可能想要使用一个完全不同的模型,独立于选择列表,作为代表 DDC 选择的支持对象。
您可能会发现以下链接很有用:
Since you're using
PropertyModel(this, "choices.0")
, Wicket is trying to find a property namedchoices
via reflection through a methodgetChoices()
of the class declaring the PropertyModel. This method doesn't seem to exist incom.samoo.tool.pages.CreatePrintingJob
, as the exception is stating.Also, if that
0
is an index, you should be accessing it with the[index]
expression, as this JIRA issue suggests: PropertyModel does not support index only property ("[0]")However, it seems you want to initialize the
DropDownChoice
to the first element ofchoices
. But What Wicket will do if you set the DropDownChoice's Model toPropertyModel(this, "choices.[0"])
will be mapping the selection of this DropDownChoice in the following way:choices
list.choices
list.Summarising, the backing object representing the
DropDownChoice
's selection would be the first element in thechoices
list.So, you'll probably want to use a whole different Model, independent from the choices list, for the backing object representing the DDC's selection.
You might find the following links useful:
您在方法内部声明选择,为了使 PropertyModel 正常工作,您需要在类级别而不是方法级别声明它。正如@Xavi López 指出的那样,表达并不正确,你需要使用选择。[0]
you are declaring choices inside the method, in order to get the PropertyModel to work you need to declare it on a class level not on a method level. As @Xavi López pointed out the espression is not corret you nedd to use choices.[0]
使用
IModel
而不是PropertyMOdel
是个好主意。PropertyModel
在重构方面存在很大问题。在我的例子中,我做到了,并且问题得到了正确解决。此外,我还覆盖了我的Topic
对象的toString()
。It is good idea to use
IModel
instead ofPropertyMOdel
.PropertyModel
has big problems in refactoring. In my cases I did it and the problems solved properly.Also I have override thetoString()
of myTopic
object.