On Wed, Oct 13, 2010 at 3:33 PM, gouthamrv <goutha...@yahoo.com> wrote:

>
> 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);
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-update-a-Panel-when-user-selects-a-drop-down-chioce-in-Wicket-tp2994412p2994412.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

The idea you have should work - you just repaint the table / panel in the
onUpdate.  However, since you are pre-loading the table with data in your
constructor, the table will not retrieve updated values based on the changed
dropdownchoice value.  Instead of calling your database or service layer in
the constructor (nearly always a bad idea), you should do that in a model,
like:

IModel<List<Foo>> listModel = new LoadableDetachableModel<List<Foo>>() {
  public List<Foo> load() {
    MyService.getLotsOfFooBasedOn(thePropertyThatIsChangedByYourDropDown);
  }
}

Doing that will make your table automatically update when it's repainted
after the drop down changes values.

-- 
Jeremy Thomerson
http://www.wickettraining.com

Reply via email to