You can use Ajax calls to add items to a normal ListView as well. Simply make sure the item to be added is added to the underlying list (typically using a LoadableDetachableModel
) in the ajaxcall, then refresh the entire listview by adding it to the AjaxRequestTarget
and setting setReuseItems
to false.
Something like:
LoadableDetachableModel<List<MyObject>> myListModel = new LoadableDetachableModel<List<MyObject>>()
{
public List<MyObject> load()
{
return generateListDynamically(); //or whatever method you use to retrieve the list including the items you've added
}
}
ListView<MyObject> items = new ListView("items", myListModel);
items.setReuseItems(false);
add(items);
//A method you call in the onclick of the link that adds or removes an item.
public void onItemAdd(AjaxRequestTarget target)
{
//should be accessible, maybe make it a member of the page or something
target.add(items);
}