A utility class often used with the {@link org.apache.tapestry.form.ListEdit} component. AListEditMap 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 {@link org.apache.tapestry.event.PageBeginRenderListener}and implement {@link org.apache.tapestry.event.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 {@link #add(Object,Object) added} to the map, in the order that items should be presented.
The {@link org.apache.tapestry.form.ListEdit}'s source parameter should be bound to the map's {@link #getKeys() keys} property. The value parameter should be bound to the map's{@link #setKey(Object) key} property.
The {@link org.apache.tapestry.form.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 {@link org.apache.tapestry.form.Checkbox}'s selected parameter to the map's {@link #isDeleted() 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 {@link #checkSet(Set)} and the mutator methodshould be a call to {@link #updateSet(Set,boolean)}.
@author Howard Lewis Ship
@since 3.0