Probably what you need is to just turn off auto refresh for that fill. Just
override autoRefresh(List params) to return false.
Since LC DS does not know what each particular query is doing, it will refresh
each query after performing an insert or update. It is looking to see if
items have been added, removed or re-ordered based on the properties you
change. In your case, maybe the query results are coming back in a completely
different order so LC DS would be trying to update the order. It might also be
that your equals/hashCode methods of your server side VOs are not defined
properly so after it does the auto-refresh it thinks the items are completely
different from the way they were originally.
Turning on the server side debug logs for the Message.* and Service.* targets
would give you a good idea of what is happening on the server.
Jeff
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Steven
Toth
Sent: Wednesday, July 16, 2008 11:53 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: DataService gives CollectionEvents for each item when
committing one item
Anyone have any experience with Data Services?
--- In flexcoders@yahoogroups.commailto:flexcoders%40yahoogroups.com, Steven
Toth [EMAIL PROTECTED] wrote:
I have a DataService that uses the Assembler interface approach (I
subclassed AbstractAssembler). When I update one item in the
managed
Collection and commit it (autoCommit is false) I'm getting a
PropertyChangeEvent of kind UPDATE for each item in the Collection
from
the DataService. In addition I get a CollectionEvent of kind
REMOVE for
each item in the Collection, then a CollectionEvent of kind ADD for
each
item in the Collection from the Collection itself.
I'm assuming this is because the fill() is being called after the
update
is completed. How do I commit/update the individual item so that I
only
get an event (or set of events) for the item that was modified? Is
that
possible when using a managed Collection or do I need to operate at
the
individual item level. Am I doing something wrong (or not doing
something at all) in the Assembler?
I'm very experienced with Remoting and Messaging but this is my
first
time dealing with DataServices. Any help, samples,etc. are greatly
appreciated. Thanks.
Here's the Assembler code...
public class MyAssembler extends AbstractAssembler {
private MyService svc = MyService.getInstance();
public Collection fill(List fillParameters) {
if (fillParameters.size() = 2) {
int fillType = FlexDataHelper.getIntPrimitive( fillParameters.get
(0) );
Long companyId = FlexDataHelper.getLong( fillParameters.get(1) );
switch(fillType) {
case QueryType.ALL_WIDGETS_FOR_COMPANY:
return svc.getAllWidgets(companyId);
case QueryType.ACTIVE_WIDGETS_FOR_COMPANY_:
return svc.getActiveWidgets(companyId);
case QueryType.WIDGETS_BY_COMPANY_AND_CATEGORY:
if (fillParameters.size() == 3) {
Integer categoryId = FlexDataHelper.getInteger( fillParameters.get
(2) );
return svc.getWidgets(companyId, categoryId);
}
}
}
// Throws a nice error
return super.fill(fillParameters);
}
public Object getItem(Map uid) {
return svc.getWidget( FlexDataHelper.getLong(uid.get(companyId)),
FlexDataHelper.getInteger(uid.get(widgetId)) );
}
public void createItem(Object newVersion) {
svc.saveWidget((WidgetValue)newVersion);
}
public void updateItem(Object newVersion, Object prevVersion, List
changes) {
try {
svc.saveWidget((WidgetValue)newVersion);
} catch (Exception e) {
Long companyId = ((WidgetValue)prevVersion).getCompanyId();
Integer widgetId = ((WidgetValue)prevVersion).getWidgetId();
System.err.println(*** Throwing DataSyncException when trying to
save
widget = + widgetId);
throw new DataSyncException(svc.getWidget(companyId, widgetId),
null);
}
}
public void deleteItem(Object prevVersion) {
try {
svc.deleteWidget( (WidgetValue)prevVersion );
} catch (Exception e) {
Long companyId = ((WidgetValue)prevVersion).getCompanyId();
Integer widgetId = ((WidgetValue)prevVersion).getWidgetId();
System.err.println(*** Throwing DataSyncException when trying to
delete
widget = + widgetId);
throw new DataSyncException(svc.getWidget(companyId, widgetId),
null);
}
}
Here's the Flex UI code...
public function getWidgetsForCompany( company:CompanyValue ):void {
var widgets:ArrayCollection = new ArrayCollection();
var call:AsyncToken = widgetService.fill(widgets,
QueryType.ALL_WIDGETS_FOR_COMPANY, company.companyId);
// Add a reference to the collection that will be filled for access
by
the responder
call.useLocalData = true;
call.localData = widgets;
call.addResponder( responder );
}
public function saveWidget( widget:WidgetValue ):void {
var call:AsyncToken;
if (isNaN(widget.widgetId)) {
call = widgetService.createItem(widget);
} else {
//Update
call = widgetService.commit(new Array(widget), false