Skip to content
Model centric tools for Spring development Community portal
Skyway PerspectivesModel driven delivery

Model reference

Reference Figure: Iterating a Collection in a Panel

The panel iterator repeats a panel for every item in a collection. This figure shows the collection source, the current item and the repeated content.

Four stacked application layers for Spring MVC and Spring Web Flow
Figure 10. The iterator binds one collection to a repeated panel block.

A panel is a reusable block of interface content. A panel iterator connects a panel to a collection and repeats the block once for every item. The panel never holds the whole list. It holds one item at a time, which keeps the template small and easy to read.

Parts of the iterator

  • Collection source. A model attribute that holds the list, usually supplied by a controller.
  • Item binding. The name used inside the panel for the current item.
  • Repeated panel. The content that is rendered for every item.
  • Empty state. The content shown when the collection has no items.

Designing the empty state

An empty collection is a normal case, not an error. Write a short empty state that explains what the user can do next, for example a link to create the first record. The generator writes the empty state from the panel settings, so it stays next to the repeated content.

Performance. Bind one collection per iterator. Nesting two iterators over large lists multiplies the rendered rows and can make a page slow. If a page needs grouped data, prepare the grouping in the controller.

The iterator figure is useful when a repeated block renders the wrong data. Check the item binding first, then the collection name. Most mistakes are a small mismatch between the two names.