Wicket-select2 dropdown is not update after provide new modelobject

786 Views Asked by At

I have wicket-select2 dropdown for country.

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

adding new country using popupPanel after click on add country button and below is functionality.

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);

page is redirect to home page but I am getting below error

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

while if i select any country then click on add button and save new country then it shows newly added country in dropdown.

1

There are 1 best solutions below

0
On

I got the answer and need to set selected country instead of setting modelObject after save country in db. see below code:

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);