When the createItem result is returned to the client, it should be
updating the id property and updating the data grid.  You are saying
that you don't see the id property updated after you commit the
createItem? 

Your suggestion of an extra attribute to the id property definition is I
think the right way to handle this.  It was part of our original plan
but just did not make it into 2.0.

Jeff

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Benno Kittelmann
Sent: Wednesday, September 27, 2006 1:43 AM
To: [email protected]
Subject: Re: [flexcoders] Add an object via DataService.createItem() to
a DataGrid

On 27/09/06, Jeff Vroom <[EMAIL PROTECTED]> wrote:
>
> But with integer ids if you call createItem twice in a row before
committing you'll end up with two objects that have 0 as their id and
that is considered an error.

What I don't understand is why a single managed object instantiated
via createItem() does not update its id value before showing up in the
DataGrid. What I initially expected is that the object gets sent to
the server, it gets persisted there and the changes propagate back to
the client, where the new values will update the managed object. Once
that object finished receiving the new values, it will passed to any
elements it is bound to (the datagrid).

Currently it seems as if a new ID value, which is getting created
server-side, is not reflected in the single-managed object, which led
to the condition I described. Which seems to odd to me, because other
newly calculated values seem appear in the object. Do I describe the
mechanism properly, and if so, what was the reason for not changing
the IDs?

I'm still a relative newbie at Flex though not in programming in
general, and this is my first FDMS project, so please bear with me if
I haven't absorbed every documentation detail yet. Will be happy if
there for any pointers regarding my particular issue.

> We should have a way to indicate that "0" is a null id....

Just from the top of my head, maybe wrap the id attribute in a
seperate object like

package myPackage
{
       [Managed]
       [RemoteClass(alias="myPackage.Item")]
       public class Item {
               public var id:Identifier = new IntegerIdentifier(0);
               public var name:String = "";

               public function setId(id:int):void {
                   id.value = int;
               }

               public function getId():int {
                  return id.value;
               }
       }
}

The IntegerIdentifier would be a subclass of an Identifier abstract
class, and the parameter used during construction would stand for the
default value if the object has not got an ID yet. With the setter and
getter pair interaction with other code would still be possible if it
passes around standard int types.

I haven't thought deeply about possible implications of this approach,
as an alternative an annotation mechnism or some mapping files a la
Hibernate come to my mind.

> In any case, I have worked around this in the past by using an
> ascending sequence of negative numbers for the ids of newly created
items.
> You just some need some integer which gets decremented each time you
> call createItem and use that value as your "id" before you call
createItem.
> That way the ids are unique before the commit call is made as well as
after.

As a workaround I used something similar, creating large random
integers to be used as IDs. The actual result set from the database is
quite small so it wasn't a problem yet, though a potential clash of
IDs is of course possible. Your suggestion to use negative IDs is
better and easier to understand, so I will implement that instead.

> Of course that could cause problems if your server allocates negative
> id values as well but hopefully that is not the case.

That won't be the case indeed. :)

Thanks for the enlightenment and best regards,
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






 




--
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