|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.tapestry.form.ListEditMap
A utility class often used with the ListEdit
component. A
ListEditMap is loaded with data objects before the ListEdit renders, and again before the
ListEdit rewinds. This streamlines the synchronization of the form against data on the server. It
is most useful when the set of objects is of a manageable size (say, no more than a few hundred
objects).
The map stores a list of keys, and relates each key to a value. It also tracks a deleted flag for each key.
Usage:
The page or component should implement PageBeginRenderListener
and implement
PageBeginRenderListener.pageBeginRender(org.apache.tapestry.event.PageEvent)
to initialize the map.
The external data (from which keys and values are obtained) is queried, and each key/value pair
is added
to the map, in the order that items should be presented.
The ListEdit
's source parameter should be bound to the map's
keys
property. The value parameter should be bound to the map's
key
property.
The ListEdit
's listener parameter should be bound to a listener
method to synchronize a property of the component from the map.
public void synchronize()
{
ListEditMap map = ...;
Type object = (Type)map.getValue();
if (object == null)
...
setProperty(object);
}
You may also connect a Checkbox
's selected parameter to the
map's deleted
property.
You may track inclusion in other sets by subclassing ListEditMap and implementing new boolean
properties. The accessor method should be a call to checkSet(Set)
and the mutator method
should be a call to updateSet(Set, boolean)
.
Constructor Summary | |
ListEditMap()
|
Method Summary | |
void |
add(java.lang.Object key,
java.lang.Object value)
Records the key and value into this map. |
protected boolean |
checkSet(java.util.Set set)
Returns true if the set contains the current key . |
protected java.util.List |
convertSetToList(java.util.Set set)
Invoked to convert a set into a List. |
java.util.List |
getAllValues()
Returns all the values stored in the map, in the order in which values were added to the map using add(Object, Object) . |
java.util.List |
getDeletedKeys()
Returns the deleted keys in an unspecified order. |
java.lang.Object |
getKey()
Returns the current key within the map. |
java.util.List |
getKeys()
Returns a List of keys, in the order that keys were added to the map (using add(Object, Object) . |
java.lang.Object |
getValue()
Returns the value for the key (set using setKey(Object) ). |
java.util.List |
getValues()
Returns all the values stored in the map, excluding those whose id has been marked deleted, in the order in which values were added to the map using add(Object, Object) . |
boolean |
isDeleted()
Returns true if the current key is in the set of deleted keys. |
void |
purgeDeletedKeys()
Removes keys and values that are in the set of deleted keys, then clears the set of deleted keys. |
void |
setDeleted(boolean value)
Adds or removes the current key from the set of deleted keys. |
void |
setKey(java.lang.Object key)
Sets the key for the map. |
protected java.util.Set |
updateSet(java.util.Set set,
boolean value)
Updates the set, adding or removing the current key from it. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ListEditMap()
Method Detail |
public void add(java.lang.Object key, java.lang.Object value)
getKeys()
. This also sets the current key (so that you may invoke
setDeleted(boolean)
, for example).
public java.util.List getKeys()
add(Object, Object)
. The caller must not modify the List.
public void setKey(java.lang.Object key)
getValue()
, isDeleted()
, setDeleted(boolean)
.
public java.lang.Object getKey()
public java.lang.Object getValue()
setKey(Object)
). May return null if no
such key has been added (this can occur if a data object is deleted between the time a form
is rendered and the time a form is submitted).
public boolean isDeleted()
current key
is in the set of deleted keys.
protected boolean checkSet(java.util.Set set)
current key
. Returns false is the set
is null, or doesn't contain the current key.
public void setDeleted(boolean value)
current key
from the set of deleted keys.
protected java.util.Set updateSet(java.util.Set set, boolean value)
current key
from it. Returns the
set passed in. If the value is true and the set is null, an new instance of HashSet
is created and returned.
public java.util.List getDeletedKeys()
public void purgeDeletedKeys()
getValues()
and getAllValues()
will
return equivalent lists and getKeys()
will no longer show any of the deleted keys.
Note that this method does not change the current key. Subclasses that track
additional key sets may want to override this method to remove deleted keys from those key
sets.
protected java.util.List convertSetToList(java.util.Set set)
set
- a set (which may be empty or null)
public java.util.List getAllValues()
add(Object, Object)
.
public java.util.List getValues()
add(Object, Object)
.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |