Attempt to set model object on null model of component

来源:互联网 发布:iphone6在线伪装软件 编辑:程序博客网 时间:2024/06/16 02:26

wicket开发web项目是遇到这个异常,分析总结如下:


1.在采用单个值的控件如input:textfield,label等,其默认值可以为单个String,定义这些控件同时默认指定一个Model给它,并且提供对应String的get方法。如下:

定义label:

Label updateInfo = new Label("updateInfo", new PropertyModel<String>(this, "updateInfo"));

get函数:

public String getUpdateInfo() {return updateInfo;}

2.在采用选项有多个,默认值为单个的控件如RadioChoice(只能选一个),不仅要提供选项Model,一般为List类型,而且还需提供默认值Model,一般为String类型。如下:



定义RadioChoice:
final RadioChoice<String> updatePastTimeChoice = new RadioChoice<String>("pastTimeChoice",new Model<String>(pastTime), new PropertyModel<List<String>>(this, "pastTimeList"));

上面代码中pastTime为默认值Model,pastTimeList为选项Model。
get函数:
public List<String> getPastTimeList() {pastTimeList = googleNews_Constants.pastTimeList;return pastTimeList;}

3.总结:

即对于控件所对应的每一项都不能为NULL,在定义时应为其设置Model,否则会出现异常。

新手或者不熟悉总会碰到这样的问题。

0 0
原创粉丝点击