我有一个Wicket下拉列表,它显示页面中的国家/地区列表,下面是java文件中的代码
new DropDownChoice("CountryList",
new PropertyModel(Country, "site"),
params.getPopCountryList(),
new ChoiceRenderer("countryName", "countryId")
).add(new AjaxFormComponentUpdatingBehavior("onchange"){
@Override
protected void onUpdate(AjaxRequestTarget target) {
//do some code here
}
});
和Country.java就像
public class Country{
private Site site = null;
public Site getSite() {
if (site == null) {
site = new Site();
site.setSiteName("Expired ID");
site.setSiteId(siteId);
}
return site;
}
public void setSite(Site site) {
this.site = site;
}
}
和Site有countryName和countryId setter和getter。现在当我更改下拉列值然后低于错误时:
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor102.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:258)
... 36 more
Caused by: org.apache.wicket.util.convert.ConversionException: Could not convert value: Armenia to type: com....model.Site. Could not find compatible converter.
at org.apache.wicket.ConverterLocator$DefaultConverter.convertToObject(ConverterLocator.java:121)
at org.apache.wicket.core.util.lang.PropertyResolverConverter.convert(PropertyResolverConverter.java:95)
at org.apache.wicket.core.util.lang.PropertyResolver$MethodGetAndSet.setValue(PropertyResolver.java:1194)
at org.apache.wicket.core.util.lang.PropertyResolver$ObjectAndGetSetter.setValue(PropertyResolver.java:651)
at org.apache.wicket.core.util.lang.PropertyResolver.setValue(PropertyResolver.java:151)
at org.apache.wicket.model.AbstractPropertyModel.setObject(AbstractPropertyModel.java:131)
at org.apache.wicket.Component.setDefaultModelObject(Component.java:3082)
at org.apache.wicket.markup.html.form.FormComponent.setModelObject(FormComponent.java:1579)
at org.apache.wicket.markup.html.form.FormComponent.updateModel(FormComponent.java:1097)
at org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior.onEvent(AjaxFormComponentUpdatingBehavior.java:151)
at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:155)
at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:593)
我也调试了这个问题,错误发生在Ajax的onupdate方法之前。请建议。
更新:下面是参数POJO中的getPopCountryList代码。
public List<Site> getPopCountryList() {
return popCountryList;
}
public void setPopCountryList(List<Site> popCountryList) {
this.popCountryList = popCountryList;
}
以及设置countryList的代码。
List<Site> countryList;
countryList = dao.getcoutryList();
params.setPopCountryList(countryList);