1

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.

Community
  • 1
  • 1
Peter
  • 1,844
  • 2
  • 31
  • 55
  • 1
    You have to set model for Dropdownchoice. – soorapadman Oct 19 '15 at 12:59
  • A Model that holds the List or a Model that holds the choice? – Peter Oct 19 '15 at 13:14
  • i don't know why you are setting model like this? Dropdownchoice is String you are setting model Collection? at the same time how this StepPersoenlicheDaten will call under page? i have many confusion? why don't you create variable for the dropdown add getter/setter then set propertymodel? – soorapadman Oct 19 '15 at 13:20
  • model should be choice. – soorapadman Oct 19 '15 at 13:21
  • 1
    Add private String sprachenDrop; include getter/setter.then add(korrespondenzsprache = new DropDownChoice("sprachenDrop", new PropertyModel(this,"sprachenDrop"),sprachen)); It Should work. – soorapadman Oct 19 '15 at 13:26
  • 1
    I tried something simular to this earlier, although it didn't work. But now I understand what the mistake was :) Would you like to change the comment to an answear, so I can accept it? – Peter Oct 19 '15 at 14:02

1 Answers1

1

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.

Peter
  • 1,844
  • 2
  • 31
  • 55
soorapadman
  • 4,451
  • 7
  • 35
  • 47
  • That works but now you're making your page into your model object. Please don't do that, that is bad form. It would be better to make add a private field `private IModel spracheModel;` and do `spracheModel = Model.of((String)null); add(korrespondenzsprache = new DropDownChoice ("sprachenDrop", spracheModel, sprachen));` After form submission `spracheModel.getObject()` would give you the picked language. – Buurman Nov 05 '15 at 13:13