【问题标题】:wicket form clear choice after refresh刷新后检票口形式明确选择
【发布时间】:2018-06-04 06:58:28
【问题描述】:

我目前在一个应用程序中使用三种不同的表单,RadioChoice、DateField 和 DropDownChoice,其中页面根据用户从该表单中选择的内容做出反应。这里的问题是,当我提交使用 DateField 和 DropDownChoice 的表单时,它会刷新页面并记住 RadioChoice 中的选择,但会显示默认选择。所以我的问题是是否可以清除这些值并在刷新后将它们设置回默认值,或者使 DateField 和 DropDownChoice 的提交不刷新页面?

    //RADIO CHOICE
    RadioChoice<String> radioChoice = new RadioChoice<String>("radio", new PropertyModel<String>(this, "selectedRadio"),this.radioChoiceList);
    radioChoice.add(new AjaxFormChoiceComponentUpdatingBehavior()
    {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target)
        {
         target.appendJavaScript(changeBaseLayerJS(Page.this.currentMap, Page.this.selectedRadio)); 
         Page.this.currentMap = Page.this.selectedRadio;
        }
    });
    Form<?> radioForm = new Form<Void>("radioForm");        
    add(radioForm);
    radioForm.add(radioChoice);


    //DATEFIELD AND DROPDOWNCHOICE
    DateField fromDateField = new DateField("fromDateField", new PropertyModel<Date>(
            this, "fromDate"));
    DateField toDateField = new DateField("toDateField", new PropertyModel<Date>(
            this, "toDate"));
    DropDownChoice<String> idvNameMenu = new DropDownChoice<String>("idvNameMenu", new PropertyModel<String>(this, "idvTrackName"), individualChoiceList);
    Form<?> trackingForm = new Form<Void>("trackingForm"){
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() 
        {
            //do stuff
        }   
    };

【问题讨论】:

    标签: java apache wicket wicketstuff


    【解决方案1】:

    普通(非 Ajax)表单提交会导致整页重绘。 Ajax 表单提交只会重绘您放入AjaxRequestTarget 的组件。

    您可以使用 form.add(new AjaxFormSubmittingBehavior() {...}) 来使用 Ajax。

    或者你可以zero-fy 你在onSubmit中建模对象:

    @Override
    protected void onSubmit() 
    {
        // do stuff
        // save in database
        fromDate = null; // or = new Date();
        toDate = null; 
        idvTrackName = "some good default value";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-30
      • 2013-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-28
      • 2012-04-18
      相关资源
      最近更新 更多