Wicket Guard #3

ListView vs DataView/ListProvider

One thing to remember when using DataView instead of ListView is that the DataView does not have a setListProvider(), neither the ListProvider has a setList(). In other words, once these objects are initialized with the list, there is no way to set another new List object. ListView has a setList() which can be called for eg during a onSubmit() to update the list.

The correct way to handle that is, on refreshing, clear out the old items from the list and add new items. When the page/form is displayed again, the new values will be used.

For eg

  List list = new ArrayList();
  //list.add(...)
  DataView dv = new DataView("dataView", new ListProvider("listProvider", list));

  protected void onSubmit() {
    list.clear();
    list.add(...);
    //thats it, no need, (rather cannot) set the list to ListProvider again
  }

So when querying list from say Spring’s JdbcTemplate queryList() methods, be aware that it returns a new List object, which the ListProvider will not pickup. You can simply do a list.clear(), followed by list.addAll(newList);