首页 > 解决方案 > 刷新后检票口形式明确选择

问题描述

我目前在一个应用程序中使用三种不同的表单,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
        }   
    };

标签: javaapachewicketwicketstuff

解决方案


正常(非 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";
}

推荐阅读