[英]PropertyModel Expression's Exception : org.apache.wicket.WicketRuntimeException: No get method defined for class:
I used PropertyModel
as the part of my DropDownChoice
as following: 我使用
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);
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?
有人可以帮忙吗?
Since you're using PropertyModel(this, "choices.0")
, Wicket is trying to find a property named choices
via reflection through a method getChoices()
of the class declaring the PropertyModel. 由于你正在使用
PropertyModel(this, "choices.0")
,Wicket试图通过声明PropertyModel的类的方法getChoices()
通过反射找到一个名为choices
的属性。 This method doesn't seem to exist in com.samoo.tool.pages.CreatePrintingJob
, as the exception is stating. com.samoo.tool.pages.CreatePrintingJob
似乎不存在此方法,因为异常是在说明。
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]") 此外,如果
0
是索引,则应使用[index]
表达式访问它,因为此JIRA问题表明: PropertyModel不支持仅索引属性(“[0]”)
However, it seems you want to initialize the DropDownChoice
to the first element of choices
. 但是,您似乎希望将
DropDownChoice
初始化为choices
的第一个元素。 But What Wicket will do if you set the DropDownChoice's Model to PropertyModel(this, "choices.[0"])
will be mapping the selection of this DropDownChoice in the following way: 但是如果你将DropDownChoice的模型设置为
PropertyModel(this, "choices.[0"])
Wicket会做什么,将以下列方式映射DropDownChoice的选择:
choices
list. choices
列表中的第一个元素。 choices
list. choices
列表的第一个位置。 Summarising, the backing object representing the DropDownChoice
's selection would be the first element in the choices
list. 总而言之,表示
DropDownChoice
选择的后备对象将是choices
列表中的第一个元素。
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. 因此,对于代表DDC选择的后备对象,您可能希望使用与选项列表无关的完全不同的模型。
List<String> choices = Arrays.asList(new String[] { "Library", "School Office",
"Science Dept" });
String selected = "Library";
IModel dropdownModel = new Model<String>(choices[0]);
DropDownChoice<String> serviceDDC =
new DropDownChoice<String>("service", dropdownModel, choices);
You might find the following links useful: 您可能会发现以下链接很有用:
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. 你在方法中声明了选择,为了使PropertyModel工作,你需要在类级别而不是在方法级别上声明它。 As @Xavi López pointed out the espression is not corret you nedd to use choices.[0]
正如@XaviLópez所指出的那样,表达方式并不正确,你需要使用选择。[0]
It is good idea to use IModel
instead of PropertyMOdel
. 最好使用
IModel
而不是PropertyMOdel
。 PropertyModel
has big problems in refactoring. PropertyModel
在重构方面存在很大问题。 In my cases I did it and the problems solved properly.Also I have override the toString()
of my Topic
object. 在我的情况下,我做了它并且问题正确解决。我也覆盖了我的
Topic
对象的toString()
。
topicDropDown = new DropDownChoice<Topic>("topicOptions", new IModel<Topic>() {
@Override
public Topic getObject() {
return top;
}
@Override
public void setObject(Topic t) {
top = t;
}
@Override
public void detach() {
}
}, new LoadableDetachableModel<List<Topic>>() {
@Override
protected List<Topic> load() {
List<Topic> topics = top.getAllTopics();
return topics;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.