【问题标题】:Wicket not updating page after form submit表单提交后检票不更新页面
【发布时间】:2012-12-20 04:09:24
【问题描述】:

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

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

【问题讨论】:

  • 您能否添加您的代码以提交表单(以防这与您的问题有关)?
  • 这是整个代码(我没有从 onSubmit 中删除任何内容)——它不应该自动更新这两个值吗,因为它们是 DropDownChoice 模型的一部分?

标签: wicket


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-10-22
    • 1970-01-01
    • 2016-10-02
    • 1970-01-01
    • 2012-05-25
    • 1970-01-01
    相关资源
    最近更新 更多