gpt4 book ai didi

java - 尝试在组件 : DropDownChoice 的空模型上设置模型对象

转载 作者:行者123 更新时间:2023-11-30 07:52:04 24 4
gpt4 key购买 nike

我正在使用 Wicket 口向导让用户执行多个步骤进行注册。
但不知怎的,我得到了这个错误:

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 附带了一个能够将列表作为模型的构造函数,因此我认为我的代码应该可以工作。

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

未被接受。

最佳答案

创建一个本地字符串,例如private String sprachenDrop; 并添加 getters/setters。然后添加:

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

应该可以。

关于java - 尝试在组件 : DropDownChoice 的空模型上设置模型对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33214777/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com