开发者

How to update a Panel when user selects a drop down choice in Wicket?

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>();
         开发者_JAVA技巧   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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜