java - 刷新后检票口形式明确选择
问题描述
我目前在一个应用程序中使用三种不同的表单,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
}
};
解决方案
正常(非 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";
}
推荐阅读
- python - python子进程运行c++任务读取文件报错
- javascript - 获取所有选定的项目以及在 jquery 中单击它的位置
- java - FTPS 登录错误:命令序列无效(身份验证前需要 AUTH SSL/TLS)
- xslt - 使用 xsl:evaluate 评估 XPath 的值
- python - 生成带替换的随机整数列表的最佳方法
- javascript - Vue & Jest。子组件发出事件时调用测试方法
- apache-spark - PySpark:如何读取 json 文件中键值对所在的所有 json 文件,例如:{“LOB”:“Auto”}
- autohotkey - autohotkey如何激活最后打开的窗口来改变它的pid
- c - 检查输入数字是否为素数的功能已损坏,但代码似乎没有任何问题
- json - 在 dotnet core 中解析这个 JSON 的最佳方法是什么?