필자는 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());
}
}
}
나는 새로운 뒤따라야를 입력 및 제출 (submit) 버튼을 누르면, 새로운 값은 텍스트 필드에서 유지됩니다. 나중의 작품은 다음과 같이 멋지지만, 이해하기 위해서이다. 그는 PropertyModel이 oldUser로 여전히 돌아가고 client.getSessionUser()에 의해 oldUser를 얻었을 때 왜 내 Textfield를 업데이트 하는가? 백엔드에는 업데이트가 없습니다.
동일한 웹 페이지에서 필자는 다른 Panel을 얻었습니다. 업데이트 방법은 아직 구현되지 않았기 때문에 그는 아직 도착 client.getSessionUser()에 의해 oldUser 있지만
@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")));
}
}
은 또한이 라벨은 새로운 값으로 설정합니다.
누군가 PropertyModels이 oldUser 대신 newUser를 참조하는 이유를 설명 할 수 있기를 바랍니다. 나는 ... PropertyMode (oldUser처럼
모델 일.formForename = new TextField("forename1", new PropertyModel(oldUser, "forename"));
와
당신이 속성에 대한 당신의 oldUser에 대한 참조를 설정하는 방법은
어리석은 질문. 당신의 도움을 주셔서 감사합니다. 방금 getter 메소드와 관련된 모델로 작업했습니다. 이제는 모델이 setter 메소드에서도 작동한다는 것을 알게되었습니다 ... – user1090145
ReadOnlyModels도 있습니다. – rotsch
ReadModel은 무엇입니까? 충돌을 얻으므로 백엔드에서 내 사용자를 업데이트하는 중에 오류가 발생하지만 프론트 엔드에서는 propertymodel에 의해 업데이트됩니다. 아니면 어떤 대체 방법이 있습니까? – user1090145