Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 642

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Flex and AIR Integration in ColdFusion
<cfelseif operation eq "DELETE">
</cfif>
<cfelse><!----Conflict--->
<cflog text = "is a conflict">
<cfset conflict = CreateObject("component","CFIDE.AIR.conflict")>
<cfset conflict.serverobject = serverobject>
<cfset conflict.clientobject = clientobject>
<cfset conflict.originalobject = originalobject>
<cfset conflict.operation = operation>
<cfset conflicts[conflictcount++] = conflict>
<cfcontinue>
</cfif>
</cfif>
</cfloop>
<cfif conflictcount gt 1>
<cfreturn conflicts>
</cfif>
</cffunction>
The CFC handling of the conflict depends on your application. In some cases, it can be appropriate to ignore the
conflict and update the server data source with the new client data. In many cases, as in the preceding example, the
CFC informs the client about the conflict by returning the server value of the data.
On the client side, you use code such as the following to register the method that handles the conflict that the server
returns.
syncmanager.addEventListener(ConflictEvent.CONFLICT, conflictHandler);
function conflictHandler(event:ConflictEvent):void
{
var conflicts:ArrayCollection = event.result as ArrayCollection;
var token:SessionToken = session.keepAllServerObjects(conflicts);
token.addResponder(new mx.rpc.Responder(conflictSuccess, conflictFault));
}
The conflictevent object contains an array of conflict objects that contain the clientinstance, originalinstance and the
serverinstance. To accept the server's data, the application calls keepAllServerObjects, which takes an ArrayCollection
that was passed to the conflict handler, or call the keepServerObject that takes an individual Conflict instance as shown
in the following code. This conflict handler simply accepts any returned server object.
function conflictHandler(event:ConflictEvent):void
{
var conflicts:ArrayCollection = event.result as ArrayCollection;
var conflict:Conflict = conflicts.getItemAt(0);
var token:SessionToken = session.keepServerObject(conflict);
token.addResponder(new mx.rpc.Responder(conflictSuccess, conflictFault));
}
Conflicts can happen in the following cases:
• When the client does an update after the server data was updated. In this case, the client was using an old instance
of data and not the latest data on the server. The server can inform the client by creating an instance of conflict.cfc
in the sync method and setting the server instance on it. On the client side, you can call the keepServerObject
function in the conflict handler to resolve the conflict by updating the client database with the server instance.
<cfset obj = ORMGetSession().merge(originalobject)>
<cfset EntityDelete(obj)>
Last updated 1/20/2012
637

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents