tags:

views:

23

answers:

1

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);
A: 

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.

Don Roby
I have found the problem, now it is working as expected. But I am seeing one more issue with navigation bar message and numbers that it shows. First time when I load page, it shows "showing 1 to 10 of 50", now I clicked next arrow link and it shows "showing 11 to 20 of 50". After this, I changed my drop down chioce to get another list from data base. I am expecting that my table should display "showing 1 to 10 of 50", but instead it is shows "showing 11 to 20 of 50" (this is the last display message before changing drop down). How do I solve this problem?
goutham
@goutham: There's likely some paging data in the table mechanism you're using that needs to be reset when you change lists. Post your DealHistoryTablePanel code and I might be able to help.
Don Roby
I found the solution for this. That is, calling table.setCurrentPage(0); after drop down value change. Thanks anyway for looking into this.
goutham