Class RefreshingView<T>

Type Parameters:
T - type of elements contained in the model's list
All Implemented Interfaces:
Serializable, Iterable<Component>, IEventSink, IEventSource, IFeedbackContributor, IConverterLocator, IMetadataContext<Serializable,Component>, IHeaderContributor, IRequestableComponent, IHierarchical<Component>, IClusterable
Direct Known Subclasses:
AbstractPageableView

public abstract class RefreshingView<T> extends RepeatingView
An abstract repeater view that provides refreshing functionality to its subclasses. The view is refreshed every request, making it well suited for displaying dynamic data.

The view is populated by implementing getItemModels() and populateItem(Item) methods. RefreshingView builds the items that will be rendered by looping over the models retrieved from getItemModels() and calling the newItem(String, int, IModel) to generate the child item container followed by a call to populateItem(Item) to let the user populate the newly created item container with custom components.

The provided ModelIteratorAdapter can make implementing getItemModels() easier if you have an iterator over item objects.

Author:
Igor Vaynberg (ivaynberg)
See Also:
  • Constructor Details

  • Method Details

    • onPopulate

      protected final void onPopulate()
      Refresh the items in the view. Delegates the creation of items to the selected item reuse strategy
      Overrides:
      onPopulate in class RepeatingView
      See Also:
    • newItemFactory

      Create a new IItemFactory based upon the RefreshingView
      Returns:
      An Item factory that delegates to the RefreshingView
    • getItemModels

      protected abstract Iterator<IModel<T>> getItemModels()
      Returns an iterator over models for items that will be added to this view
      Returns:
      an iterator over models for items that will be added to this view
    • populateItem

      protected abstract void populateItem(Item<T> item)
      Populate the given Item container.

      be careful to add any components to the item and not the view itself. So, don't do:

       add(new Label("foo", "bar"));
       
      but:
       item.add(new Label("foo", "bar"));
       

      Parameters:
      item - The item to populate
    • newItem

      protected Item<T> newItem(String id, int index, IModel<T> model)
      Factory method for Item container. Item containers are simple MarkupContainer used to aggregate the user added components for a row inside the view.
      Parameters:
      id - component id for the new data item
      index - the index of the new data item
      model - the model for the new data item
      Returns:
      DataItem created DataItem
      See Also:
    • getItems

      public Iterator<Item<T>> getItems()
      Returns:
      iterator over item instances that exist as children of this view
    • addItems

      protected void addItems(Iterator<Item<T>> items)
      Add items to the view. Prior to this all items were removed so every request this function starts from a clean slate.
      Parameters:
      items - item instances to be added to this view
    • getItemReuseStrategy

      Returns:
      currently set item reuse strategy. Defaults to DefaultItemReuseStrategy if none was set.
      See Also:
    • setItemReuseStrategy

      Sets the item reuse strategy. This strategy controls the creation of Items.
      Parameters:
      strategy - item reuse strategy
      Returns:
      this for chaining
      See Also: