0

I have a Wicket dropdown which is showing country list in page, below is code in java file

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

and Country.java is like

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

and Site is having countryName and countryId setter and getter. Now when I changes the dropdown value then getting below error :

    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)

I have also debug this issue, error comes before onupdate method of Ajax. Please suggest.

UPDATE : below is the code for getPopCountryList in parameters POJO.

public List<Site> getPopCountryList() {
    return popCountryList;
}


public void setPopCountryList(List<Site> popCountryList) {
    this.popCountryList = popCountryList;
}

and also below code for setting countryList.

List<Site> countryList;
countryList = dao.getcoutryList();
params.setPopCountryList(countryList);
nitin
  • 83
  • 1
  • 9
  • 2
    You are using Raw-types for all the generic wicket classes you use. Don't do that! (see: [What is a raw type and why shouldn't we use it?](https://stackoverflow.com/q/2770321/6073886)). If your `DropDownChoice` refers to the type Site you should use `DropDownChoice`. Same for PropertyModel and ChoiceRenderer. But i am also confused about your DropDown in general: Are you supposed to choose a Country from it or a Site? Your PropertyModel seems to refer to a Site while the ChoiceRenderer and Choices look like they Point to Countries. – OH GOD SPIDERS Nov 17 '17 at 19:30
  • I am choosing country from it like country.getSite.getCountryName in the dropdown. If you please tell me about error log it will be helpful to me. – nitin Nov 18 '17 at 07:49
  • 1
    It seems getPopCountryList() returns a list of strings. Can you show us that code too? – svenmeier Nov 18 '17 at 11:38
  • @svenmeier I have updated my question with brief detail. Please check – nitin Nov 19 '17 at 09:57
  • 1
    @svenmeier Thanks for your suggestion. Its works fine, I have debug again and find that getPopCountryList() returns a list of Country instead of Site after that its resolved. – nitin Nov 19 '17 at 11:28
  • Have you solved it? If not, can you show the code of dao.getcoutryList()? – tomrlh Jan 31 '18 at 02:51
  • @tomurlh yes I have already mention the resolution in above your comment. It's classcastType issue. – nitin Feb 06 '18 at 10:45

0 Answers0