javawicketdropdownchoice

Attempt to set model object on null model of component: DropDownChoice


I'm using a wicket Wizard to let the user take multiple steps for a registration.
But Somehow I get this error:

Last cause: Attempt to set model object on null model of component: wizard:form:view:sprachenDrop

WicketMessage: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at [Form [Component id = form]] on component [Form [Component id = form]] threw an exception

And this snippet from the stack trace:

Root cause:
java.lang.IllegalStateException: Attempt to set model object on null model of component: wizard:form:view:sprachenDrop at org.apache.wicket.Component.setDefaultModelObject(Component.java:3038) at org.apache.wicket.markup.html.form.FormComponent.setModelObject(FormComponent.java:1577) at org.apache.wicket.markup.html.form.FormComponent.updateModel(FormComponent.java:1098) at org.apache.wicket.markup.html.form.Form$FormModelUpdateVisitor.component(Form.java:230) at org.apache.wicket.markup.html.form.Form$FormModelUpdateVisitor.component(Form.java:200)

Refering to this post I tried to create a class to hold the information I need, but it didn't work, I took this tutorial as basic. From Wicket's help itself I tried this code and thus created an IClusterable class to hold the information. The error was still the same. Since DropDownChoice comes with a constructor able to hold a List as Model I thought that my code should work.

public class StepPersoenlicheDaten  extends WizardStep{
    private static final long serialVersionUID = 1L;
    private RequiredTextField<String> name, vorname, strasse, ort, telefonNr;
    private DropDownChoice<String> korrespondenzsprache;
    private List<String> sprachen = new ArrayList<String>();


    public StepPersoenlicheDaten(WizardModel model) {
        super(new ResourceModel("daten.title"), new ResourceModel("daten.summary"));
        init(model);
        java.util.Collections.addAll(sprachen, "Deutsch","English","Français","Italiano");

        add(name = new RequiredTextField<String>("name", Model.of("")));
        add(vorname = new RequiredTextField<String>("vorname",  Model.of("")));
        add(strasse = new RequiredTextField<String>("strasse",  Model.of("")));
        add(ort = new RequiredTextField<String>("ort",  Model.of("")));
        add(telefonNr = new RequiredTextField<String>("telefonNr", Model.of("")));
        add(korrespondenzsprache = new DropDownChoice<String>("sprachenDrop", sprachen));
    }
}

The error appears when I click the finish (or next) button on the wizard. I don't know what else I could try to fix it.

Edit:

IModel<Collection<? extends String>> langs = Model.of(sprachen);
add(korrespondenzsprache = new DropDownChoice<String>("sprachenDrop", langs));

Was not accepted.


Solution

  • Create a local string like private String sprachenDrop; and add getters/setters. Then add:

    add(korrespondenzsprache = new DropDownChoice<String>("sprachenDrop", 
    new PropertyModel(this, "sprachenDrop"), sprachen));
    

    It Should work.