RE: [flexcoders] LCDS - adding a new Item using createItem()

2009-01-20 Thread Jeff Vroom
There are actually two tokens for that operation - one returned from the 
createItem call itself.   It is actually a subclass of AsyncToken called 
ItemReference.  It has a bindable result value which gets set when the result 
comes in.First we'll deliver the result event for the createItem's token, 
then we deliver it for the batch itself.

The result for the commit token is not going to be the newly created item but 
the result for the createItem's token should be that item.

I'm still not sure why you are not seeing your id get set though... it should 
be set in the very same instance you pass to createItem.   The client and 
server debug logs would be the best way to track that down.

Jeff

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Besite - Bart
Sent: Tuesday, January 20, 2009 1:22 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] LCDS - adding a new Item using createItem()


Hi,

Below is some code from my test application.  I am trying to create a new 
user-object using the createItem() method of my AbstractAssembler.
I have bound an event listener to my DataService that listens for ResultEvents. 
 The  resultHandler is called twice when createItem()  is called.

The first time the resultHandler is called, I get back my user-object, but with 
id 0 and event.token.kind = undefined.  So I have two problems,
why is the id of my user 0 (when I print it out serverside the id of the 
user-object is different from 0) and why is event.token.kind undefined (instead 
of create)...

The second time the resultHandler is called event.token.kind equals create 
and the result is a mx.messaging.messages.AcknowledgeMessageExt

I hope you can help me out here...

Bart

My Flex code :

private function init():void
{
ds = new DataService(user);
ds.addEventListener(ResultEvent.RESULT,resultHandler);
ds.autocommit = false;
}

private function createUser():void
{
 var user:User = new User(Jeff);
 ds.createItem(user)

 var token:AsyncToken = ds.commit();
 token.kind = create;
}

private function resultHandler(event:ResultEvent):void
{
 if(event.token.kind == create)
 {
...
 }
 else
 {
  
 }
}

Java code  :

UserAssembler.java

   ...

   public void createItem(Object item)
   {
  UserDAO dao = new UserDAO();

  User newUser = (User) item;

  User user = dao.createUser(newUser);

  System.out.println(UserId  + user.getId());
   }

Kind Regards
Bart


Jeff Vroom schreef:
As long as your assembler's createItem method populates identity property of 
the item passed in, it should be returned to the client and updated there when 
the commit response is received by the client. To help diagnose why this is 
not happening, first upgrade to 2.6.1 (on the product download page) since it 
has better diagnostics than the earlier versions.   Secondly, enable the 
server's debug log target for Service.*.In the logs, should see it calling 
your createItem method and what value gets returned for the identity property.  
If it all looks correct there, check the client mx:TraceTarget/ logs and make 
sure that value makes it back to the client.   It should indicate in the client 
logs that it is updating the cache and that the id property is getting updated 
there.

Jeff

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Besite - Bart
Sent: Sunday, January 18, 2009 5:25 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] LCDS - adding a new Item using createItem()


Hello,

In my Data Management Service I create a new User-object using the
createItem() function :

ds.createItem(new User(Jeff));
var token:AsyncToken = ds.commit();
token.kind = create;

When the commit is sent, the new User is persisted to the server... In
my database an autoincrement id is generated,
but the object returned to the Flex client has still an id equal to 0.

How do I know the unique id of the created User-object on the
client-side ? I need this unique id to do some remote calls as soon as
it is created on the server...

Any help is welcome !

Kind regards
Bart


inline: image001.jpginline: image002.jpg

RE: [flexcoders] LCDS - adding a new Item using createItem()

2009-01-19 Thread Jeff Vroom
As long as your assembler's createItem method populates identity property of 
the item passed in, it should be returned to the client and updated there when 
the commit response is received by the client. To help diagnose why this is 
not happening, first upgrade to 2.6.1 (on the product download page) since it 
has better diagnostics than the earlier versions.   Secondly, enable the 
server's debug log target for Service.*.In the logs, should see it calling 
your createItem method and what value gets returned for the identity property.  
If it all looks correct there, check the client mx:TraceTarget/ logs and make 
sure that value makes it back to the client.   It should indicate in the client 
logs that it is updating the cache and that the id property is getting updated 
there.

Jeff

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Besite - Bart
Sent: Sunday, January 18, 2009 5:25 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] LCDS - adding a new Item using createItem()


Hello,

In my Data Management Service I create a new User-object using the
createItem() function :

ds.createItem(new User(Jeff));
var token:AsyncToken = ds.commit();
token.kind = create;

When the commit is sent, the new User is persisted to the server... In
my database an autoincrement id is generated,
but the object returned to the Flex client has still an id equal to 0.

How do I know the unique id of the created User-object on the
client-side ? I need this unique id to do some remote calls as soon as
it is created on the server...

Any help is welcome !

Kind regards
Bart

inline: image001.jpginline: image002.jpg