RecordSet.setDeliveryMode( )

RecordSet.setDeliveryMode( ) MethodFlash 6

returns paged resultsets from ColdFusion
myRecordSet.setDeliveryMode(mode, pagesize, numPrefetchPages)



The mode to use in fetching pages from the server ("ondemand", "fetchall", or "page").


The number of records to return in each page (required in "fetchall" and "page" modes).


The number of pages to retrieve from the server (required in "page" mode).


The setDeliveryMode( ) method allows you to set the mode of pageable resultsets from a ColdFusion Server. The different modes are:


The delivery mode is "ondemand" by default. It simply means that the records are returned when they are requested. Use "ondemand" mode when each record is needed individually and at different times. Do not use this mode if you are iterating through the entire recordset at once, because it forces the client to make a separate request for each record, which is very inefficient. The mode is efficient only if you won't eventually load all the records and you want to limit network traffic to only those records that must be loaded. Also, it is fine for small recordsets where all records will download at once.


Using the "fetchall" parameter allows you to grab a page at a time, but in batches. The size of each batch is specified in the pagesize argument. Use "fetchall" mode when you know that you are going to load all the data but would like to start displaying the data incrementally rather than having to wait for it all to load. For example, if you know you have 300 records to load, it makes sense to load them over the course of 10 requests, 30 records at a time, so that you can start displaying data as soon as possible.


Using "page" mode allows you to retrieve one page at a time. You must also specify the pagesize and numPrefetchPages arguments. The "page" mode lies somewhere between "ondemand" and "fetchall". Use "page" mode when you don't expect to need all the data in the recordset, but you don't want the overhead of loading each record individually. For example, you don't want to make the user wait for 10 pages of search results to load, because he will most likely find what he needs in the first two or three pages. Therefore, load the first two or three pages initially, then load the other pages as they are needed.


The following code creates a pageable recordset and sets the delivery mode to "page":

#include ""

var my_conn = NetServices.createGatewayConnection( );
var customerService = my_conn.getService("com.oreilly.frdg.Customers", this);
// Set a global RecordSet variable
var myRS;
// Create the PushButton. Assumes FPushButtonSymbol is already in Library.
//Position and label the PushButton
with (submit_pb) {
  _x = 300;
  _y = 35;
// Call the remote method once, retrieving 10 records

function getNext( ) {
  var recordNum = myRs.getNumberAvailable( );
  // Attempt to get a record past the last record available.
  // This will cause the paging to kick in and retrieve another set of records.
  // If the recordset is fully downloaded, display it in the Output window
  if (recordNum == myRS.getLength( ))
    for (var i=0; i<recordNum; i++)

function getCustomers_Result(result_rs) {
  myRS = result_rs;
  result_rs.setDeliveryMode("page", 10);
  // Trace the number of records available. This statement executes only once.
  trace("onresult: " + myRs.getNumberAvailable( ));

This self-contained code operates against the Customers service from Chapter 5. It demonstrates recordset paging using the "page" mode. Each time the user clicks a button, the getNext( ) function attempts to retrieve a record that is beyond the end of the number of records available. When this happens, the next set of records is returned from the server. Note that when you click the button, the Output window displays the number of records from the getNext( ) function, but the getCustomers_Result( ) function is never called again; Flash Remoting takes care of the recordset paging, and the responder method onResult event is never triggered again.

Chapter 5 contains a complete example of recordset paging and demonstrates the setDeliveryMode( ) method in greater detail.

See Also

RecordSet.getNumberAvailable( ), RecordSet.isFullyPopulated( ); Chapter 4 and Chapter 5

    Part III: Advanced Flash Remoting