我的页面构造函数中有这段代码:
private String selectedAwsId;
private String selectedIsReal;
//these two are actually outside the constructor, and getters and setters for these two strings not shown
List<AwsCredentials> awsCredentials = (List<AwsCredentials>)getAwsCredentials();
List<String> awsIds = new ArrayList<String>();
for (AwsCredentials cred : awsCredentials){
awsIds.add(cred.getAwsId());
}
selectedAwsId = awsIds.get(0);
List<String> yesOrNo = Arrays.asList(new String[] { "sandbox", "real"});
selectedIsReal = "sandbox";
Form selectAwsCredentialsForm = new Form("selectAwsCredentialsForm"){
@Override
public void onSubmit() {
super.onSubmit();
//TODO: why isn't this updating the form?
}
};
add(selectAwsCredentialsForm);
selectAwsCredentialsForm.add(new DropDownChoice("selectAwsCredentialsDropdown", new PropertyModel(this, "selectedAwsId"), awsIds));
selectAwsCredentialsForm.add(new DropDownChoice("selectRealOrSandboxHitsDropdown", new PropertyModel(this, "selectedIsReal"), yesOrNo));
我第一次渲染页面时,效果很好。但是,当我更改任一 DropDownChoices 中的选择并提交表单时,页面不会更改( selectedAwsId 和 selectedIsReal 中的值不会相应更改)。在我对表单如何工作的理解中,我是否遗漏了什么?提交表单时是否刷新整个页面(构造函数是否再次运行?)