当用户在 Wicket 中选择下拉选项时如何更新面板?
我想知道当我们选择下拉选择值时如何更新面板,即在 onUpdate() 方法中。
我的自定义面板有 AjaxFallbackDefaultDataTable。
下面是面板和下拉组件代码。当用户选择日期时,我想替换整个面板。目前我已经评论了 target.addComponent 代码,但我想在这里实现。有什么建议吗?
List<DealHistory> dealHistoryList = ServicesCaller
.getAllDealHistoryRecords();
DealHistoryTablePanel dealHistoryTablePanel = new DealHistoryTablePanel(
"deal_history_table_panel", dealHistoryList);
dealHistoryTablePanel.setOutputMarkupId(true);
add(dealHistoryTablePanel);
IModel<List<? extends String>> dateChoices = new AbstractReadOnlyModel<List<? extends String>>() {
@Override
public List<String> getObject() {
List<String> list = new ArrayList<String>();
list.add("Last 3 months");
list.add("Last 6 months");
return list;
}
};
final DropDownChoice<String> datesDropDown = new DropDownChoice<String>(
"dates", new PropertyModel<String>(this, "selectedDate"),
dateChoices);
datesDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
//target.addComponent(dealHistoryTablePanel);
}
});
add(datesDropDown);
I would like to know how to update a panel when we select a drop down chioce values, that is in onUpdate() method.
My custom panel has AjaxFallbackDefaultDataTable.
Below is Panel and drop down components code. When user selects date, I want to replace my entire Panel. Currently I have commened that target.addComponent code, but I want to have implementation here. Any suggestions?
List<DealHistory> dealHistoryList = ServicesCaller
.getAllDealHistoryRecords();
DealHistoryTablePanel dealHistoryTablePanel = new DealHistoryTablePanel(
"deal_history_table_panel", dealHistoryList);
dealHistoryTablePanel.setOutputMarkupId(true);
add(dealHistoryTablePanel);
IModel<List<? extends String>> dateChoices = new AbstractReadOnlyModel<List<? extends String>>() {
@Override
public List<String> getObject() {
List<String> list = new ArrayList<String>();
list.add("Last 3 months");
list.add("Last 6 months");
return list;
}
};
final DropDownChoice<String> datesDropDown = new DropDownChoice<String>(
"dates", new PropertyModel<String>(this, "selectedDate"),
dateChoices);
datesDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
//target.addComponent(dealHistoryTablePanel);
}
});
add(datesDropDown);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您绝对走在正确的道路上。实现这一目标的基本方法是
在
AjaxFormComponentUpdatingBehavior
中准确地放置它。您还可能想要更改
DealHistoryTablePanel
中的模型,可能的方法是用通过对您的服务的不同调用获取的列表替换它包含的列表。更明确地说,我必须查看DealHistoryTablePanel
的代码。示例显示选择后更新一个
DropDownChoice
一个是有启发性的,尽管它更新的组件当然是不同的。You're definitely on the right track. The basic thing that will make it happen is having the
exactly where you have it, in an
AjaxFormComponentUpdatingBehavior
.You'll also likely want to change the model in your
DealHistoryTablePanel
, probably by replacing the list it contains with one gotten by a different call to your service. To say anything more explicit, I'd have to see the code forDealHistoryTablePanel
.An example showing the updating of one
DropDownChoice
after the selction of one is instructive, though of course the component it updates is different.