Ive得到下面的代码更新User.class:检票:PropertyModel更新
@SuppressWarnings("serial")
public class UpdateProfilePanel extends Panel{
protected ServiceClientTemp client = ((WicketApplication) (WicketApplication.get())).getClient();
protected User oldUser;
protected User newUser;
public UpdateProfilePanel(String id) {
super(id);
Form updateProfileForm = new UpdateProfileForm("updateProfileForm");
add(updateProfileForm);
}
class UpdateProfileForm extends Form {
private FormComponent formForename;
private FormComponent formSurname;
private FormComponent formEmail;
public UpdateProfileForm(String id) {
super(id);
oldUser = client.getSessionUser();
formForename = new TextField("forename1", new PropertyModel(oldUser, "forename"));
formSurname = new TextField("surname1", new PropertyModel(oldUser, "surname"));
formEmail = new TextField("email1", new PropertyModel(oldUser, "email"));
add(formForename);
add(formSurname);
add(formEmail);
}
public void onSubmit() {
newUser = new User();
newUser.setForename(formForename.getInput());
newUser.setSurname(formSurname.getInput());
newUser.setEmail(formEmail.getInput());
}
}
}
当我进入一个新的名字及按我的提交按钮,新的值停留在文本字段。对于后来的作品来说,这很好,但只是为了理解:为什么他更新我的文本框,当PropertyModel仍然留给oldUser和client.getSessionUser()我仍然是老用户。后端没有更新。
在同一个WebPage上我得到了另一个面板,它给了我真正的用户信息。
@SuppressWarnings("serial")
public class UserInfoPanel extends Panel {
protected ServiceClientTemp client = ((WicketApplication) (WicketApplication.get())).getClient();
protected User infoUser;
@SuppressWarnings("rawtypes")
UserInfoPanel(String id) {
super(id);
infoUser = client.getSessionUser();
add(new Label("username", new PropertyModel(infoUser, "username")));
add(new Label("surname", new PropertyModel(infoUser, "surname")));
add(new Label("forename", new PropertyModel(infoUser, "forename")));
add(new Label("email", new PropertyModel(infoUser, "email")));
add(new Label("state", new PropertyModel(infoUser, "state")));
}
}
而且这个标签变成了新的价值,但他仍然得到了oldUser通过client.getSessionUser(),因为更新方法尚未实现。
希望有人能解释为什么PropertyModels引用newUser而不是oldUser。否则为什么是像我建立我的PropertyModel像PropertyMode(oldUser,...
我的愚蠢问题。谢谢你的帮助。我只是与模型一起使用getter方法。现在我认识到模型也可以使用setter方法... – user1090145 2012-01-15 15:01:17
也有ReadOnlyModels :) – rotsch 2012-01-15 16:00:14
什么是ReadModel?因为我遇到了冲突,所以在更新后端中的用户时发生错误时,在前端中,它会被propertymodel更新。或者是否有任何回退方法? – user1090145 2012-01-18 10:35:24