T
- public abstract class AbstractDetachableCollection<T> extends Object implements Collection<T>, org.apache.wicket.model.IDetachable, Serializable
attach()
and detach()
. Elements are converted between the two states using the
specified IDetachCodec
.
This collection allows the use of real objects, and yet has the convenience of a small session
footprint.
If the collection is detached, invocation of any method from Collection
will cause this
collection to be attached.
NOTICE: During the conversion to either state N method calls are invoked on the
IDetachCodec
, one for each element in the collection. This can cause a performance
problem in certain situations.
Example
class SelectUsersPanel extends Panel { // codec to transcode user object to and from its detached state private static final IDetachCodec<User> userCodec=new IDetachCodec<User> { public Serializable detach(User object) { return object.getId(); } public User attach(Serializable object) { return UserDao.get().userForId(object); } } // collection used to store selected user objects private final DetachableHashSet<User> selected=new DetachableHashSet<User>(userCodec); protected void onDetach() { // this will shrink the size of selected collection before the page is stored in session. // the collection will be attached automatically when some method is invoked on it. selected.detach(); super.onDetach(); } public SelectUsersPanel (String id) { super(id); Form form=new Form("form"); add(form); CheckGroup checked=new CheckGroup("checked", new PropertyModel(this, "selected")); form.add(checked); checked.add(new DataView("users", new UsersDataProvider()) { protected void populateItem(Item item) { item.add(new Check("user", item.getModel())); item.add(new Label("username", new PropertyModel(item.getModel(), "username"))); } } ... }
Constructor and Description |
---|
AbstractDetachableCollection(IDetachCodec<T> codec)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
attach()
Converts the collection into its attached state.
|
void |
detach()
Converts the collection into a detached state.
|
boolean |
equals(Object obj) |
protected Collection<T> |
getAttachedStore()
Returns collection used to store elements in attached state.
|
int |
hashCode() |
protected abstract Collection<T> |
newAttachedStore()
Creates a collection used to store elements in attached state
|
public AbstractDetachableCollection(IDetachCodec<T> codec)
codec
- codec that will be used to transcode elements between attached and detached statespublic final void attach()
public final void detach()
detach
in interface org.apache.wicket.model.IDetachable
public boolean equals(Object obj)
equals
in interface Collection<T>
equals
in class Object
protected Collection<T> getAttachedStore()
public int hashCode()
hashCode
in interface Collection<T>
hashCode
in class Object
protected abstract Collection<T> newAttachedStore()
Copyright © 2015. All rights reserved.