提供新的modelobject后,Wicket-select2下拉列表不会更新

时间:2018-01-05 14:57:50

标签: java wicket jquery-select2 wicketstuff

我有国家的wicket-select2下拉列表。

Select2Choice<Country> country = new Select2Choice<Country>("country", new PropertyModel<Country>(params, "selectedCountry"),new CountriesProvider(params));

点击添加国家/地区按钮后使用popupPanel添加新国家/地区是功能。

Country addCountry = new Country();
//provide data of country for setter and add in db and setting countrydropdown Model Object by using below code:
country.setModelObject(addCountry);
param.setCountry(countrylistUpdated);
country.setprovider(new CountryProvider);
target.add(addCountry);

页面重定向到主页但我收到以下错误

org.apache.wicket.WicketRuntimeException: Exception in rendering component: [DropDownChoice [Component id = qualityDropDown]]
at org.apache.wicket.Component.internalRenderComponent(Component.java:2589)
at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1698)
at org.apache.wicket.Component.internalRender(Component.java:2380)
at org.apache.wicket.Component.render(Component.java:2308)
at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1524)
at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1759)
at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1734)
at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1657)


........



//some more logs...
......
Caused by: java.lang.NullPointerException: List of choices is null - Was the supplied 'Choices' model empty?
at org.apache.wicket.markup.html.form.AbstractChoice.getChoices(AbstractChoice.java:233)
at org.apache.wicket.markup.html.form.AbstractChoice.onComponentTagBody(AbstractChoice.java:376)
at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:70)
at org.apache.wicket.Component.internalRenderComponent(Component.java:2565)
... 103 more

如果我选择任何国家/地区,然后点击添加按钮并保存新国家/地区,则会在下拉列表中显示新添加的国家/地区。

1 个答案:

答案 0 :(得分:0)

我得到了答案,需要在db中保存国家后设置所选国家而不是设置modelObject。见下面的代码:

Country addCountry = new Country();
//provide data of country for setter and add in db and setting countrydropdown Model Object by using below code:
country.setSelectedCountry(addCountry);
param.setCountry(countrylistUpdated);
country.setprovider(new CountryProvider);
target.add(addCountry);