我的页面构造函数中包含此代码:
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中的值不会相应地更改)。在理解表格如何运作时,我是否缺少一些东西?提交表单时是否刷新整个页面(构造函数是否再次运行?)
答案 0 :(得分:0)
您可能想要构建模型并将其设置为表单的模型。 (这就是我所做的。)提交表单(如果所有表格都已正确编码)将导致表格的模型更新。