先看一下RepeatingView:
html:
<tr wicket:id="repeating"> <td><span wicket:id="actions">[actions]</span></td> <td><span wicket:id="contactid">[contactid]</span> </td> <td><span wicket:id="firstname">[firstname]</span></td> <td><span wicket:id="lastname">[lastname]</span></td> <td><span wicket:id="homephone">[homephone]</span></td> <td><span wicket:id="cellphone">[cellphone]</span></td> </tr>
java:
RepeatingView repeating = new RepeatingView("repeating");
add(repeating);
int index = 0;
while (contacts.hasNext())
{
AbstractItem item = new AbstractItem(repeating.newChildId());
repeating.add(item);
Contact contact = contacts.next();
item.add(new ActionPanel("actions", new DetachableContactModel(contact)));
item.add(new Label("contactid", String.valueOf(contact.getId())));
item.add(new Label("firstname", contact.getFirstName()));
item.add(new Label("lastname", contact.getLastName()));
item.add(new Label("homephone", contact.getHomePhone()));
item.add(new Label("cellphone", contact.getCellPhone()));
。。。。。
如果是常规的组件,应该是repeating.add(xxx),但是repeating组件是通过创建新的item,将模板中的子组件添加到这个item中去,这就是最明显的区别。同时,这个item代表了外围的组件,你可以对它添加属性,修改属性等等。
RefreshingView:
<tr wicket:id="view"> <td><span wicket:id="itemid">[item id]</span></td> <td><span wicket:id="actions">[actions]</span></td> <td><span wicket:id="contactid">[contactid]</span> </td> <td><span wicket:id="firstname">[firstname]</span></td> <td><span wicket:id="lastname">[lastname]</span></td> <td><span wicket:id="homephone">[homephone]</span></td> <td><span wicket:id="cellphone">[cellphone]</span></td> </tr>
RefreshingView<Contact> view = new RefreshingView<Contact>("view")
{
private static final long serialVersionUID = 1L;
/**
* Return an iterator over models for items in the view
*/
@Override
protected Iterator<IModel<Contact>> getItemModels()
{
return contacts.iterator();
}
@Override
protected void populateItem(final Item<Contact> item)
{
Contact contact = item.getModelObject();
item.add(new Label("itemid", item.getId()));
item.add(new ActionPanel("actions", item.getModel()));
item.add(new Label("contactid", String.valueOf(contact.getId())));
item.add(new Label("firstname", contact.getFirstName()));
item.add(new Label("lastname", contact.getLastName()));
item.add(new Label("homephone", contact.getHomePhone()));
item.add(new Label("cellphone", contact.getCellPhone()));
item.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<String>()
{
private static final long serialVersionUID = 1L;
@Override
public String getObject()
{
return (item.getIndex() % 2 == 1) ? "even" : "odd";
}
}));
}
};
可见RefreshingView看起来更加组件化,更加OO,除此之外,我没看出有什么区别。
接下来是DataView,
DataView is a basic implementation of AbstractPageableView. Data views aim to make it very simple to populate your repeating view from a database by utilizing IDataProvider to act as an interface between the database and the dataview.
DataView是这个类分支的末端,可控性和封装都合适的实现。
DataView上面是DataViewBase,其下的类分支有:
GridView,DataGridView,这两个类的便利性增加,可控性下降。
<table cellspacing="0" cellpadding="2" border="1"> <tr wicket:id="rows"> <td wicket:id="cells"> <span wicket:id="cell">cell content goes here</span> </td> </tr> </table>
public DataGridPage()
{
List<ICellPopulator<Contact>> columns = new ArrayList<ICellPopulator<Contact>>();
columns.add(new PropertyPopulator<Contact>("id"));
columns.add(new PropertyPopulator<Contact>("firstName"));
columns.add(new PropertyPopulator<Contact>("lastName"));
columns.add(new PropertyPopulator<Contact>("homePhone"));
columns.add(new PropertyPopulator<Contact>("cellPhone"));
add(new DataGridView<Contact>("rows", columns, new SortableContactDataProvider()));
}
后两者可能更加适合存粹的数据展示,不需要交互。同时更加轻量。
原文:http://my.oschina.net/jianglibo/blog/362326