On Thu, May 27, 2010 at 3:55 PM, sahuja <[email protected]> wrote:

>
> Jeremy, I am not really sure what you mean by using a model that gets the
> columns on every repaint, but here's how I have changed my code now.
>
>    public TotalsToolbar(final DataTable table, final IModel
> dataProviderModel)
>    {
>        super(table);
>
>        WebMarkupContainer totals = new WebMarkupContainer("totals");
>        add(totals);
>
>        AbstractReportingBean row =
> (AbstractReportingBean)dataProviderModel.getObject();
>
>        List<String> totalList = new ArrayList<String>();
>         final IColumn[] columns = table.getColumns();
>        for (int i = 0; i < columns.length; i++)
>        {
>           final IColumn column = columns[i];
>            String val =
> row.getStringForFieldNamed(column.getSortProperty());
>           if (val == null || val.length() == 0) {
>               val = "&nbsp;";
>           }
>            totalList.add(val);
>        }
>
>        ListView listView = new ListView("total", totalList){
>            protected void populateItem(ListItem item) {
>                String totalItem = (String) item.getModelObject();
>                item.add(new Label("value",
> totalItem.getValue()).setEscapeModelStrings(false));
>            }
>        };
>
>        totals.add(listView);
>        return;
>    }
>
> I changed the way I was creating my toolbar to use a model wrapped around
> the data.
>
>    public GrandTotalsDataTable(String id, final List columns,
>            ISortableDataProvider sortableDataProvider, IDataProvider
> dataProvider,
>            int rowsPerPage)
>    {
>        super(id, columns, sortableDataProvider, rowsPerPage);
>        addBottomToolbar(new TotalsToolbar(this,
> dataProvider.model(dataProvider.iterator(0, 1).next())));
>    }
>
> And, here is my markup for the TotalsToolbar:
> <wicket:panel>
>  <tr>
>    [span wicket:id="totals">
>      <td wicket:id="total">
>          [span wicket:id="value">[amount][/span>
>      </td>
>    [/span>
>  </tr>
> </wicket:panel>
>
> (Changing the '<' before span tags to display it).
>
> BTW, I tried to put breakpoints like you suggested, but interestingly when
> I
> hit F5, the debugger doesn't hit any of my code. I do see the table being
> updated though...
>

This is the whole point.  You are only constructing that list of values when
the table is instantiated - which only happens on the initial view.  This is
why you don't hit breakpoints when you click a navigation link.
 Understanding this is key to using Wicket correctly - so make sure that by
the end of this exercise you have learned enough to understand what I'm
saying.

In your constructor, you are creating a list of values.  This is wrong.
 Instead, you need to do this:

IModel<List<String>> model = new LoadableDetachableModel<List<String>>() {
  List<String> load() {
    // move all of that list generation code here so that it is re-created
on every request
  }
};
new ListView("idhere", model) {
  // populateItem, etc goes here
}



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

Reply via email to