org.apache.tapestry.form
Class ListEditMap

java.lang.Object
  extended by org.apache.tapestry.form.ListEditMap

public class ListEditMap
extends Object

A utility class often used with the ListEditcomponent. 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 PageRenderListenerand implement PageRenderListener.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 addedto the map, in the order that items should be presented.

The ListEdit's source parameter should be bound to the map's keysproperty. The value parameter should be bound to the map's keyproperty.

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(IRequestCycle cycle)
     {
        ListEditMap map = ...;
        <i>Type</i> object = (<i>Type</i>)map.getValue();
    
        if (object == null)
          ...
    
        set<i>Property</i>(object);
     }
     
   
  
 

You may also connect a Checkbox's selected parameter to the map's deletedproperty.

You may track inclusion in other sets by subclasses 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).

Since:
3.0
Author:
Howard Lewis Ship

Constructor Summary
ListEditMap()
           
 
Method Summary
 void add(Object key, Object value)
          Records the key and value into this map.
protected  boolean checkSet(Set set)
          Returns true if the set contains the current key.
protected  List convertSetToList(Set set)
           
 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).
 List getDeletedKeys()
          Returns the deleted keys in an unspecified order.
 Object getKey()
          Returns the current key within the map.
 List getKeys()
          Returns a List of keys, in the order that keys were added to the map (using add(Object, Object).
 Object getValue()
          Returns the value for the key (set using setKey(Object)).
 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 keyis in the set of deleted keys.
 void setDeleted(boolean value)
          Adds or removes the current keyfrom the set of deleted keys.
 void setKey(Object key)
          Sets the key for the map.
protected  Set updateSet(Set set, boolean value)
          Updates the set, adding or removing the current keyfrom it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListEditMap

public ListEditMap()
Method Detail

add

public void add(Object key,
                Object value)
Records the key and value into this map. The keys may be obtained, in the order in which they are added, using getKeys(). This also sets the current key (so that you may invoke setDeleted(boolean), for example).


getKeys

public List getKeys()
Returns a List of keys, in the order that keys were added to the map (using add(Object, Object). The caller must not modify the List.


setKey

public void setKey(Object key)
Sets the key for the map. This defines the key used with the other methods: getValue(),isDeleted(),setDeleted(boolean).


getKey

public Object getKey()
Returns the current key within the map.


getValue

public Object getValue()
Returns the value for the key (set using 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).


isDeleted

public boolean isDeleted()
Returns true if the current keyis in the set of deleted keys.


checkSet

protected boolean checkSet(Set set)
Returns true if the set contains the current key. Returns false is the set is null, or doesn't contain the current key.


setDeleted

public void setDeleted(boolean value)
Adds or removes the current keyfrom the set of deleted keys.


updateSet

protected Set updateSet(Set set,
                        boolean value)
Updates the set, adding or removing the current keyfrom 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.


getDeletedKeys

public List getDeletedKeys()
Returns the deleted keys in an unspecified order. May return an empty list.


convertSetToList

protected List convertSetToList(Set set)

getAllValues

public 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).


getValues

public 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).