is neither getting refreshed in the same session nor across multiple
sessions, I am using Cf adapter . (The data is getting inserted into
the database correctly)
After adding a record the flex dump shows correctly the following message
[CFDataServicesAdapter] invoking SYNC method, 1 change(s) to process.
[CFDataServicesAdapter] invoking Fill method...
[Flex] After invoke service: data-service
reply: Flex Message (flex.messaging.messages.AcknowledgeMessage)
and only the record which is added is shown in this dump
My flex code
==================
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
pageTitle="data service"
creationComplete="initApp()">
<mx:Script>
<![CDATA[
import com.adobe.downloads.softwarepublishingtool.vo.ProductVersion;
import mx.controls.*;
import mx.collections.ArrayCollection;
import mx.data.DataService;
import mx.data.IManaged;
import mx.data.events.*;
import mx.messaging.events.*;
import mx.rpc.*;
import mx.rpc.events.*;
import samples.contact.*;
[Bindable]
public var contacts:ArrayCollection;
[Bindable]
public var contact:ProductVersion;
private var ds:DataService;
private function initApp():void
{
contacts = new ArrayCollection();
ds = new DataService("product");
ds.addEventListener(ResultEvent.RESULT, resultHandler);
ds.addEventListener(DataServiceFaultEvent.FAULT, faultHandler);
ds.addEventListener(DataConflictEvent.CONFLICT, conflictHandler);
ds.autoCommit = false;
var token:AsyncToken = AsyncToken(ds.fill(contacts));
token.kind = "fill";
}
private function resultHandler(event:ResultEvent):void
{
if (event.token.kind == "create")
{
dg.selectedIndex = contacts.length - 1;
}
else if (event.token.kind == "delete" && contacts.length>0)
{
var index:int = event.token.index < contacts.length ?
event.token.index : contacts.length -1;
dg.selectedIndex = index;
contact = contacts[index];
}
else if (event.token.kind == "fill" && contacts.length>0)
{
dg.selectedIndex = 0;
contact = contacts[0];
}
}
private function faultHandler(event:DataServiceFaultEvent):void
{
Alert.show(event.fault.faultstring, "Error");
if (event.item != null)
{
ds.revertChanges(event.item as IManaged);
dg.selectedItem = event.item;
contact = event.item as ProductVersion;
}
}
private function conflictHandler(event:DataConflictEvent):void
{
var conflicts:Conflicts = ds.conflicts;
var c:Conflict;
for (var i:int=0; i<conflicts.length; i++)
{
c = Conflict(conflicts.getItemAt(i));
Alert.show("Reverting to server value", "Conflict");
c.acceptServer();
}
ds.commit();
}
private function newContact():void
{
dg.selectedIndex = -1;
contact = new ProductVersion();
}
private function updateContact():void
{
if (!contacts.contains(contact))
{
ds.createItem(contact);
var token:AsyncToken = ds.commit();
token.kind = "create";
}
else if (ds.commitRequired)
{
var token:AsyncToken = ds.commit();
token.kind = "update";
}
}
private function deleteContact():void
{
var index:int = dg.selectedIndex;
ds.deleteItem(contact);
var token:AsyncToken = ds.commit();
token.kind = "delete";
token.index = index;
}
private function searchContacts():void
{
var token:AsyncToken = AsyncToken(ds.fill(contacts,
[searchText.text]));
token.kind = "fill";
}
]]>
</mx:Script>
<mx:Binding source="firstName.text" destination="contact.name"/>
<mx:Binding source="lastName.text" destination="contact.version"/>
<mx:Binding source="address.text" destination="contact.productId"/>
<mx:HDividedBox width="100%" height="100%">
<mx:Panel title="Contact List" width="100%" height="100%">
<mx:DataGrid id="dg" dataProvider="{contacts}" width="100%"
height="100%"
change="contact=ProductVersion(dg.selectedItem)" >
<mx:columns>
<mx:DataGridColumn dataField="productId" headerText="id"/>
<mx:DataGridColumn dataField="name" headerText="Name"/>
<mx:DataGridColumn dataField="version" headerText="version"/>
</mx:columns>
</mx:DataGrid>
<mx:ControlBar>
<mx:TextInput id="searchText" width="100%" enter="searchContacts()"/>
<mx:Button label="Search" click="searchContacts()" width="60"/>
</mx:ControlBar>
</mx:Panel>
<mx:Panel title="Details [{dg.selectedIndex!=-1?contact.name+'
'+contact.version:'New Contact'}]" width="100%" height="100%">
<mx:Form width="100%" height="100%" label="General">
<mx:FormItem label="Name" required="true">
<mx:TextInput id="firstName" width="250"
text="{contact.name}"/>
</mx:FormItem>
<mx:FormItem label="Version" required="true">
<mx:TextInput id="lastName" width="250"
text="{contact.version}"/>
</mx:FormItem>
<mx:FormItem label="Id">
<mx:TextInput id="address" width="250"
text="{contact.productId}"/>
</mx:FormItem>
</mx:Form>
<mx:ControlBar>
<mx:Button label="{dg.selectedIndex!=-1?'Update':'Add'}"
click="updateContact()" width="60"/>
<mx:Button label="Delete" click="deleteContact()"
visible="{dg.selectedIndex!=-1}" width="60"/>
<mx:Button label="New" click="newContact()"
visible="{dg.selectedIndex!=-1}" width="60"/>
</mx:ControlBar>
</mx:Panel>
</mx:HDividedBox>
</mx:Application>
My Coldfusion assembler code
===============================
<cfcomponent output="false">
<cffunction name="fill" output="no"
returntype="downloads.softwarepublishingtool.vo.ProductVersion[]"
access="remote">
<cfset var ret = ArrayNew(1)>
<cftry>
<cfset service = CreateObject("component",
"downloads.softwarepublishingtool.services.ProductService")>
<cfreturn service.getAllProductsWithVersions()>
<!--- If the SQL failed, mark this change with the error --->
<cfcatch type="database">
<cfset msg = "Error during fill: " & cfcatch.queryError & ". SQL
was :" & cfcatch.sql>
<cfthrow message="#msg#">
</cfcatch>
<!--- If anything else happened, mark this change with the error --->
<cfcatch type="any">
<cfset msg = "Error during fill: " & cfcatch.message >
<cfthrow message="#msg#">
</cfcatch>
</cftry>
</cffunction>
<cffunction name="sync" output="no" returnType="array" access="remote">
<cfargument name="changes" type="array" required="yes">
<!-- array for the returned changes -->
<cfset var newchanges=ArrayNew(1)>
<!-- Loop over the changes and apply them --->
<cfloop from="1" to="#ArrayLen(changes)#" index="i" >
<cfset co = changes[i]>
<cfif co.isCreate()>
<cfset x = doCreate(co)>
</cfif>
<cfset ArrayAppend(newchanges, x)>
</cfloop>
<!-- Return the change objects, as this is how success or failure is
indicated --->
<cfreturn newchanges>
</cffunction>
<cffunction name="doCreate" access="private" output="no">
<cfargument name="co" required="yes" hint="The change object.">
<!--- the record to create --->
<cfset var new = co.getNewVersion()>
<!--- TODO: Validate that all the fields are set --->
<cftry>
<cfset service = CreateObject("component",
"downloads.softwarepublishingtool.services.ProductService")>
<!--- create the record, create returns with the identity fields
set --->
<cfset service.createProductVersion(new)>
<!--- set the new version in to the change object --->
<cfset co.setNewVersion(new)>
<!--- mark this change as processed successfully --->
<cfset co.processed()>
<!--- If the SQL failed, mark this change with the error --->
<cfcatch type="database">
<cfset msg = "Error during create: " & cfcatch.queryError & ". SQL
was :" & cfcatch.sql>
<cfset co.fail(msg)>
</cfcatch>
<!--- If anything else happened, mark this change with the error --->
<cfcatch type="any">
<cfset msg = "Error during create: " & cfcatch.message >
<cfset co.fail(msg)>
</cfcatch>
</cftry>
<!--- Return the change object --->
<cfreturn co>
</cffunction>
<cffunction name="doUpdate" access="private" output="no">
<cfargument name="co" required="yes" hint="The change object.">
<!--- the record to update --->
<cfset var new = co.getNewVersion()>
<cfset var old = co.getPreviousVersion()>
<cftry>
<cfset service = CreateObject("component",
"downloads.softwarepublishingtool.services.ProductService")>
<!--- update the record --->
<cfset new = service.updateProduct(old, new)>
<!--- mark this change as processed successfully --->
<cfset co.processed()>
<!--- If the SQL failed, mark this change with the error --->
<cfcatch type="database">
<cfset msg = "Error during update: " & cfcatch.queryError & ". SQL
was :" & cfcatch.sql>
<cfset co.fail(msg)>
</cfcatch>
<!--- If anything else happened, mark this change with the error --->
<cfcatch type="any">
<cfset msg = "Error during update: " & cfcatch.message >
<cfset co.fail(msg)>
</cfcatch>
</cftry>
<!--- Return the change object --->
<cfreturn co>
</cffunction>
<cffunction name="doDelete" access="private" output="no">
<cfargument name="co" required="yes" hint="The change object.">
<!--- the record to delete --->
<cfset var old = co.getPreviousVersion()>
<cftry>
<cfset service = CreateObject("component",
"downloads.softwarepublishingtool.services.ProductService")>
<!--- delete the record --->
<cfset service.deleteProduct(old)>
<!--- mark this change as processed successfully --->
<cfset co.processed()>
<!--- If the SQL failed, mark this change with the error --->
<cfcatch type="database">
<cfset msg = "Error during delete: " & cfcatch.queryError & ". SQL
was :" & cfcatch.sql>
<cfset co.fail(msg)>
</cfcatch>
<!--- If anything else happened, mark this change with the error --->
<cfcatch type="any">
<cfset msg = "Error during delete: " & cfcatch.message >
<cfset co.fail(msg)>
</cfcatch>
</cftry>
<!--- Return the change object --->
<cfreturn co>
</cffunction>
</cfcomponent>
My config settings
================
<adapters>
<adapter-definition id="coldfusion-dao"
class="coldfusion.flex.CFDataServicesAdapter" default="true"/>
</adapters>
<default-channels>
<channel ref="cf-dataservice-rtmp"/>
</default-channels>
<destination id="product">
<adapter ref="coldfusion-dao" />
<properties>
<metadata>
<identity property="productId"/>
<identity property="id"/>
</metadata>
<network>
<session-timeout>0</session-timeout>
<paging enabled="false" size="10" />
<throttle-inbound policy="ERROR" max-frequency="500"/>
<throttle-outbound policy="REPLACE"
max-frequency="500"/>
</network>
<server>
<assembler>
<component>downloads.softwarepublishingtool.assemblers.product_assembler</component>
<singleton>true</singleton>
</assembler>
<fill-method>
<name>fill</name>
</fill-method>
<sync-method>
<name>sync</name>
</sync-method>
</server>
</properties>
</destination>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
| Web site design development | Computer software development | Software design and development |
| Macromedia flex | Software development best practice |
YAHOO! GROUPS LINKS
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

