当用户在 Wicket 中选择下拉选项时如何更新面板?

发布于 2024-09-27 12:09:52 字数 1352 浏览 4 评论 0原文

我想知道当我们选择下拉选择值时如何更新面板,即在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫雪独思 2024-10-04 12:09:52

您绝对走在正确的道路上。实现这一目标的基本方法是

target.addComponent(dealHistoryTablePanel);

AjaxFormComponentUpdatingBehavior 中准确地放置它。

您还可能想要更改 DealHistoryTablePanel 中的模型,可能的方法是用通过对您的服务的不同调用获取的列表替换它包含的列表。更明确地说,我必须查看 DealHistoryTablePanel 的代码。

示例显示选择后更新一个 DropDownChoice一个是有启发性的,尽管它更新的组件当然是不同的。

You're definitely on the right track. The basic thing that will make it happen is having the

target.addComponent(dealHistoryTablePanel);

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 for DealHistoryTablePanel.

An example showing the updating of one DropDownChoice after the selction of one is instructive, though of course the component it updates is different.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文