|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.wicket.Component org.apache.wicket.MarkupContainer org.apache.wicket.markup.html.WebMarkupContainer org.apache.wicket.markup.repeater.AbstractRepeater org.apache.wicket.markup.html.list.ListView
public abstract class ListView
A ListView is a repeater that makes it easy to display/work with List
s. However, there
are situations where it is necessary to work with other collection types, for repeaters that
might work better with non-list or database-driven collections see the
org.apache.wicket.markup.repeater package.
Also notice that in a list the item's uniqueness/primary key/id is identified as its index in the
list. If this is not the case you should either override getListItemModel(IModel, int)
to return a model that will work with the item's true primary key, or use a different repeater
that does not rely on the list index.
A ListView holds ListItem children. Items can be re-ordered and deleted, either one at a time or
many at a time.
Example:
<tbody> <tr wicket:id="rows" class="even"> <td><span wicket:id="id">Test ID</span></td> ...
Though this example is about a HTML table, ListView is not at all limited to HTML tables. Any kind of list can be rendered using ListView.
The related Java code:
add(new ListView("rows", listData) { public void populateItem(final ListItem item) { final UserDetails user = (UserDetails)item.getModelObject(); item.add(new Label("id", user.getId())); } });
NOTE:
When you want to change the default generated markup it is important to realize that the ListView
instance itself does not correspond to any markup, however, the generated ListItems do.
This means that methods like Component.setRenderBodyOnly(boolean)
and
Component.add(org.apache.wicket.behavior.IBehavior)
should be invoked on the ListItem
that
is given in populateItem(ListItem)
method.
WARNING: though you can nest ListViews within Forms, you HAVE to set the
setReuseItems property to true in order to have validation work properly. By default,
setReuseItems is false, which has the effect that ListView replaces all child components by new
instances. The idea behind this is that you always render the fresh data, and as people usually
use ListViews for displaying read-only lists (at least, that's what we think), this is good
default behavior.
However, as the components are replaced before the rendering starts, the search for specific
messages for these components fails as they are replaced with other instances. Another problem is
that 'wrong' user input is kept as (temporary) instance data of the components. As these
components are replaced by new ones, your user will never see the wrong data when setReuseItems
is false.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.apache.wicket.Component |
---|
Component.ComponentModelChange, Component.EnabledChange, Component.IVisitor, Component.VisibilityChange |
Field Summary |
---|
Fields inherited from class org.apache.wicket.Component |
---|
ENABLE, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PATH_SEPARATOR, RENDER |
Constructor Summary | |
---|---|
ListView(java.lang.String id)
|
|
ListView(java.lang.String id,
IModel model)
|
|
ListView(java.lang.String id,
java.util.List list)
|
Method Summary | |
---|---|
java.util.List |
getList()
Gets the list of items in the listView. |
protected IModel |
getListItemModel(IModel listViewModel,
int index)
Subclasses may provide their own ListItemModel with extended functionality. |
boolean |
getReuseItems()
If true re-rendering the list view is more efficient if the windows doesn't get changed at all or if it gets scrolled (compared to paging). |
int |
getStartIndex()
Get index of first cell in page. |
int |
getViewSize()
Based on the model object's list size, firstIndex and view size, determine what the view size really will be. |
Link |
moveDownLink(java.lang.String id,
ListItem item)
Returns a link that will move the given item "down" (towards the end) in the listView. |
Link |
moveUpLink(java.lang.String id,
ListItem item)
Returns a link that will move the given item "up" (towards the beginning) in the listView. |
protected ListItem |
newItem(int index)
Create a new ListItem for list item at index. |
protected void |
onBeginPopulateItem(ListItem item)
Comes handy for ready made ListView based components which must implement populateItem() but you don't want to lose compile time error checking reminding the user to implement abstract populateItem(). |
protected void |
onPopulate()
Callback to let the repeater know it should populate itself with its items. |
protected abstract void |
populateItem(ListItem item)
Populate a given item. |
Link |
removeLink(java.lang.String id,
ListItem item)
Returns a link that will remove this ListItem from the ListView that holds it. |
protected void |
renderChild(Component child)
Render a single child. |
protected void |
renderItem(ListItem item)
Render a single item. |
protected java.util.Iterator |
renderIterator()
Returns an iterator for the collection of child components to be rendered. |
Component |
setList(java.util.List list)
Sets the model as the provided list and removes all children, so that the next render will be using the contents of the model. |
Component |
setModel(IModel model)
Sets the model and removes all current children, so that the next render will be using the contents of the model. |
ListView |
setReuseItems(boolean reuseItems)
If true re-rendering the list view is more efficient if the windows doesn't get changed at all or if it gets scrolled (compared to paging). |
ListView |
setStartIndex(int startIndex)
Set the index of the first item to render |
ListView |
setViewSize(int size)
Define the maximum number of items to render. |
Methods inherited from class org.apache.wicket.markup.repeater.AbstractRepeater |
---|
onBeforeRender, onRender |
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer |
---|
getMarkupType, getWebPage |
Methods inherited from class org.apache.wicket.MarkupContainer |
---|
add, addOrReplace, autoAdd, autoAdd, contains, findMarkupStream, get, getAssociatedMarkupStream, getMarkupStream, hasAssociatedMarkup, internalAdd, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onComponentTagBody, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, replace, setMarkupStream, size, toString, toString, visitChildren, visitChildren |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ListView(java.lang.String id)
Component.Component(String)
public ListView(java.lang.String id, IModel model)
Component.Component(String, IModel)
public ListView(java.lang.String id, java.util.List list)
id
- See Componentlist
- List to cast to SerializableComponent.Component(String, IModel)
Method Detail |
---|
public final java.util.List getList()
public boolean getReuseItems()
public final int getStartIndex()
public int getViewSize()
public final Link moveDownLink(java.lang.String id, ListItem item)
id
- Name of move-down link component to createitem
-
public final Link moveUpLink(java.lang.String id, ListItem item)
id
- Name of move-up link component to createitem
-
public final Link removeLink(java.lang.String id, ListItem item)
id
- Name of remove link component to createitem
-
public Component setList(java.util.List list)
list
- The list for the new model. The list must implement Serializable
.
public Component setModel(IModel model)
setModel
in class MarkupContainer
model
- The new model
MarkupContainer.setModel(org.apache.wicket.model.IModel)
public ListView setReuseItems(boolean reuseItems)
reuseItems
- Whether to reuse the child items.
public ListView setStartIndex(int startIndex)
startIndex
- First index of model object's list to display
public ListView setViewSize(int size)
size
- Number of items to display
protected IModel getListItemModel(IModel listViewModel, int index)
listViewModel
- The ListView's modelindex
- The list item index
protected ListItem newItem(int index)
index
-
protected final void onPopulate()
AbstractRepeater
onPopulate
in class AbstractRepeater
AbstractRepeater.onPopulate()
protected void onBeginPopulateItem(ListItem item)
item
- protected abstract void populateItem(ListItem item)
be careful to add any components to the list item. So, don't do:
add(new Label("foo", "bar"));but:
item.add(new Label("foo", "bar"));
item
- The item to populateprotected final void renderChild(Component child)
AbstractRepeater
renderChild
in class AbstractRepeater
child
- Child component to be renderedAbstractRepeater.renderChild(org.apache.wicket.Component)
protected void renderItem(ListItem item)
item
- The item to be renderedprotected java.util.Iterator renderIterator()
AbstractRepeater
renderIterator
in class AbstractRepeater
AbstractRepeater.renderIterator()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |