1

我的页面构造函数中有这段代码:

    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 中的值不会相应更改)。在我对表单如何工作的理解中,我是否遗漏了什么?提交表单时是否刷新整个页面(构造函数是否再次运行?)

4

1 回答 1

0

您可能想要构建一个模型并将其设置为表单的模型。(这就是我所做的。)提交表单(如果所有代码都正确编码)将导致表单的模型被更新。

于 2012-12-20T19:29:28.950 回答