IPE - ItemPendingError
page - A contiguous block of list items.
Remote data collection sources, like mx.data.DataService, can provide lazy access to remote collections. Rather than making the local application wait until the entire collection has been transferred from the remote service, contiguous blocks of collection items called "pages" are transferred as needed. An IList implementation that supports paging notifies the local client that an item is not yet available - because the corresponding page request is pending - by throwing an ItemPendingError (IPE).
The Halo List and DataGrid classes handle IPEs internally. The corresponding Spark classes, DataGroup and the classes that depend on DataGroup, do not.
This feature simplifies writing Spark applications that display lists of remote paged data by eliminating the need to handle ItemPendingErrors. An IList wrapper class called AsyncListView automatically handles ItemPendingErrors thrown when items are requested with the IList getItemAt() method. A Spark List or DataGroup can be configured to work correctly with a remote source by wrapping it's dataProvider with a AsyncListView object. For example:
<s:List>
<mx:AsyncListView list="{myDataProvider}"/>
</s:List>
By default, AsyncListView items that are pending an internal page request, as well as items whose request failed, are null. It's often useful to be able to specify the placeholder item for a pending request, or for a failure. The AsyncListView createPendingItemFunction and createFailedItemFunction properties can be used to specify "factory" functions that produce pending and failed items. Here's an example:
<s:List>
<mx:AsyncListView list="{myDataProvider}"
createPendingItemFunction="createPendingItem"
createFailedItemFunction="createFailedItem"/>
</s:List>
<fx:Script>
private function createPendingItem(index:int, ipe:ItemPendingError):Object
{
return "<a href="%26quot%3B%20%2B%20index%20%2B%20%26quot%3B%20...">" + index + " ...</a>";
}
private function createFailedItem(index:int, info:Object):Object
{
return "<a href="%26quot%3B%20%2B%20index%20%2B%20%26quot%3B%20failed">" + index + " failed</a>";
}
</fx:Script>
The AsyncListView class implements IList and has-a IList property called "list". Most of its methods simply delegate to the list property.
package mx.collections
{
/**
* A wrapper for IList implementations that handles ItemPendingErrors
* thrown by getItemAt(), removeItemAt(), and toArray().
*
* The getItemAt() method handles ItemPendingErrors by returning a provisional
* "pending" item until the underlying request succeeds or fails. The provisional
* item is produced by calling createPendingItemFunction. If the request
* succeeds, the actual item replaces the provisional one, and if it fails
* the provisional item is replaced by with the item returned by calling
* createFailedItemFunction.
*
* This class delegates the IList methods and properties to its list.
* If a list isn't specified, methods that mutate the collection are no-ops,
* and methods that query the collection return an "empty" value like null or zero
* as appropriate.
*
* This class is intended to be used with Spark components based on DataGroup,
* like List and ComboBox, which don't provide intrinsic support for ItemPendingError handling.
*
* AsyncListView does not support re-insertion of pending or failed items. Once
* a failed or pending item is removed, its connection to a pending request for data
* is lost. Using drag and drop to move a pending item in an ASyncListView, or sorting
* an ASyncListView that contains pending or failed items, is not supported because
* these operations remove and then re-insert list items.
*/
public class AsyncListView extends OnDemandEventDispatcher implements IList
{
/**
* AsyncListView constructor.
*
* @param list Initial value of the list property, the IList we're delegating to.
*/
public function AsyncListView(list:IList = null)
<a href="Inspectable%28category%3D%26quot%3BGeneral%26quot%3B%29">Inspectable(category="General")</a>
<a href="Bindable%28%26quot%3BlistChanged%26quot%3B%29">Bindable("listChanged")</a>
/**
* The IList that this collection view "wraps", i.e. the object to which all of
* the IList metods are delegated.
*
* If this property is null, the IList mutation methods, like setItemAt(),
* are no-ops and the IList query methods, like getItemAt() return, null
* or zero (-1 for getItemIndex()), as appropriate.
*
* @default null
*/
public function get list():IList
public function set list(value:IList):void
/**
* A function that's used to create a provisional item when
* the initial request causes an ItemPendingError to be thrown.
* If the request eventually succeeds, the provisional item is automatically
* replaced by the actual item. If the request fails, then the item is replaced
* with one created with the createFailedItemFunction.
*
* The value of this property must be a function with two parameters, the index
* of the requested dataProvider item, and the ItemPendingError itself. In most
* cases second parameter can be ignored, e.g.:
*
* function createPendingItem(index:int, ipe:ItemPendingError):Object
* {
* return "<a href="%26quot%3B%20%2B%20index%20%2B%20%26quot%3Brequest%20is%20pending...">" + index + "request is pending...</a>";
* }
*
* Setting this property does not affect provisional pending items that were already
* created. Setting this property to null will prevent provisional pending items
* from being created.
*/
public function get createPendingItemFunction():Function
public function set createPendingItemFunction(value:Function):void
/**
* A function that's used to create a substitute item when
* a request which had caused an ItemPendingError to be thrown,
* subsequently fails. The existing item, typically a pending item created
* with the value of createPendingItemFunction(), is replaced
* with the failed item.
*
* The value of this property must be a function with two parameters, the index
* of the requested item, and the failure "info" object, which is
* passed along from the IResponder fault() method. In most cases second parameter
* can be ignored, e.g.:
*
* function createFailedItem(index:int, info:Object):Object
* {
* return "<a href="%26quot%3B%20%2B%20index%20%2B%20%26quot%3Brequest%20failed">" + index + "request failed</a>";
* }
*
* Setting this property does not affect failed items that were already
* created. Setting this property to null will prevent failed items from being created.
*
*/
public function get createFailedItemFunction():Function
public function set createFailedItemFunction(value:Function):void
/**
* Returns the value of list.getItemAt(index).
*
* This method catches ItemPendingErrors (IPEs) generated as a consequence of
* calling getItemAt(). If an IPE is thrown, an IResponder is added to
* the IPE and a provisional "pending" item, created with the
* createPendingItemFunction is returned. If the underlying request
* eventually succeeds, the pending item is replaced with the real item. If it fails,
* the pending item is replaced with a value produced by calling
* createFailedItemFunction.
*
* @param index The list index from which to retrieve the item.
* @param prefetch An int indicating both the direction
* and number of items to fetch during the request if the item is not local.
* @throws RangeError if index < 0 or index >= length.
* @return The list item at the specified index.
*/
public function getItemAt(index:int, prefetch:int=0):Object
/**
* Removes the actual, failed, or pending item at the specified index and
* returns it. All items whose index is greater than the specified index are shifted
* to the left.
*
* If there isn't an actual or pending item at the specified index, for
* example because a call to getItemAt(index) hasn't caused the data to be
* paged in, then the underlying list may throw an IPE. The
* implementation ignores the IPE and returns null.
*
* @param index The list index from which to retrieve the item.
* @throws RangeError if index < 0 or index >= length.
* @return The item that was removed or null.
*/
public function removeItemAt(index:int):Object
/**
* Returns an array with the same elements as this AsyncListView. The array is initialized
* by retrieving each item with getItemAt(), so pending items will be substituted where actual
* values aren't available yet. The array will not be updated when the ASyncList replaces
* the pending items with actual (or failed) values.
*/
public function toArray():Array
// Remaining IList methods ommitted for clarity
}
}