我正在使用檢票嚮導讓用戶採取多個步驟進行註冊。
但不知何故,我得到這個錯誤:嘗試在零組件的模型上設置模型對象:DropDownChoice
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
而從堆棧跟蹤這個片段:
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)
指的this post我試圖創建一個類來保存我需要的信息,但它沒沒有工作,我以this tutorial爲基礎。從Wicket的幫助本身,我嘗試了this code,從而創建了一個IClusterable類來保存信息。錯誤仍然是一樣的。由於DropDownChoice
帶有一個構造函數,能夠將List作爲模型,所以我認爲我的代碼應該可以工作。
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));
}
}
單擊向導上的完成(或下一個)按鈕時會顯示錯誤。我不知道還有什麼我可以嘗試修復它。
編輯:
IModel<Collection<? extends String>> langs = Model.of(sprachen);
add(korrespondenzsprache = new DropDownChoice<String>("sprachenDrop", langs));
是不能接受的。
您必須爲Dropdownchoice設置模型。 – soorapadman
保存列表或保存選擇的模型的模型? –
我不知道你爲什麼要設置這樣的模型? Dropdownchoice是你正在設置模型集合的字符串?同時這個StepPersoenlicheDaten將如何在頁面下調用?我有很多困惑?爲什麼不爲下拉菜單創建變量添加getter/setter然後設置propertymodel? – soorapadman