Hello all,

I have the following (simplified) setup: An ArrayCollection is bound
to the dataProvider attribute of a DataGrid. The values of the
ArrayCollection are loaded by a DataService during startup of the
application. Additionally, there is a form which is used to create new
managed objects. Whenever the form is submitted, a new object is
created, and after a call to to createItem() it is persisted on the
server, and some seconds later displayed in the DataGrid. So far so
good.

Here's the problem though: If I try to directly add another object, I
get the error message "Item with id '0' already exists'. And the
object does not display in the DataGrid.

The object I'm trying to add/persist looks like this:

package myPackage
{
        [Managed]
        [RemoteClass(alias="myPackage.Item")]
        public class Item {
                public var id:int;
                public var name:String = "";            
        }
}

and I'm trying to persist it like this:

var newItem:Item = new Item();
newItem.name = "foobar";
dataservice.createItem(newItem);
                        
datagrid.dataProvider.refresh();
Alert.show(String(newItem.id)); 


The alert is showing me '0' as the newly generated id - which I
suppose is to be expected, since the order of method calls is not
synchronous. Anyway, when I monitor what's happening on the server, I
see that a new Java object is successfully created and persisted to
the database, and it gets the ID value set from the ORM tool
(Hibernate). I suspected that then the dataservice notifies the Flash
client that a new object exists, and that it should display it. My
assumption was that the managed Item object would then have the newly
generated ID instead of the default '0' value.

I have the feeling I'm probably not doing things in the correct order
or missing a crucial piece of information. How is one supposed to
persist a managed object via createItem() and put that into a
DataGrid? Does any article exist that showcases this situation? I've
perused the Flex docs extensively, but did not find a good example
that helped me resolve my problem.

Thanks in advance,
Benno Kittelmann


--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/flexcoders/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to