Example > Basic, columns


All tables on that page show the same table. The differences are in the java code only.
	<table>
	    <thead>...</thead>
	    <tbody>
	        <tr 
wicket:id="rows"
id="rows" class="even"> <td><span
wicket:id="id"
>Test ID</span></td> <td><span
wicket:id="name"
>Test Name</span></td> <td><span
wicket:id="email"
>Test EMail</span></td> <td><span
wicket:id="status"
>Test Status</span></td> <td><span
wicket:id="comments"
>Test Comments</span></td> </tr> </tbody> </table>

It can be as simple as that, provided some assumptions are met:
  add(new SimpleListView("rows", data));
ID Name Email Status Comments
Test ID Test Name Test EMail Test Status Test Comments
Test ID Test Name Test Email Test Status Test Comments

Lets say the property has a different name: "description" instead of "comments":
  add(new SimpleListView("rows", data)
  {
      public void populateItem(final ListItem listItem)
      {
          final ListObject value = (ListObject) listItem.getModelObject();

          // You only need to manually add the components where
          // a) the tag id is NOT equal to the wicket id
          // b) you need something else than a Label
          // c) you need to attach AttributeModifier
          // d) any other fancy stuff
          listItem.add(new Label("comments", value.getDescription()));
      }
  });
ID Name Email Status Comments
Test ID Test Name Test EMail Test Status Test Comments

Instead of using SimpleListView, the following example uses ListView and shows how easy it is to implement some of the functionality of SimpleListView:
  add(new ListVieweWithAlternatingRowStyle("rows", data)
  {
      public void populateItem(final ListItem listItem)
      {
          // you see. No more model required
          listItem.add(new Label("id"));
          listItem.add(new Label("name"));
          listItem.add(new Label("email"));
          listItem.add(new Label("status"));
          listItem.add(new Label("description"));
      }

      // This makes the trick
      protected IModel getListItemModel(final IModel model, final int index)
      {
          return new CompoundPropertyModel(super.getListItemModel(model, index));
      }
  });
ID Name Email Status Comments
Test ID Test Name Test EMail Test Status Test Comments

And this is the most basic way to do it:
  add(new ListVieweWithAlternatingRowStyle("rows", data)
  {
      public void populateItem(final ListItem listItem)
      {
          final ListObject value = (ListObject) listItem.getModelObject();

          listItem.add(new Label("id", Integer.toString(value.getId())));
          listItem.add(new Label("name", value.getName()));
          listItem.add(new Label("email", value.getEmail()));
          listItem.add(new Label("status", value.getStatus()));
          listItem.add(new Label("comments", value.getDescription()));
      }
  });
ID Name Email Status Comments
Test ID Test Name Test EMail Test Status Test Comments