namtax
January 20, 2010, 10:48am
1
Hi there
Am a bit stuck and wondered if anyone could assist
I am creating a new entity through the coldbox framework, so i have a
form which submits to the following handler
void function save(event) output=false{
var rc = event.getCollection();
rc.user= taskService.getUser(event.getValue("iUserID",""));
populateModel(rc.user);
userService.save(rc.user);
}
The userService.save method looks like this
void function save(User user) output=false{
transaction {
entitySave(arguments.user);
}
}
What I would like to do, is drag the ID of the newly created user so I
can setNextEvent to that new users home page eg setNextEvent(users/
home/id=2)
Any ideas?
Many thanks
Just ask the object what its id is. It is populated on the object when
it is inserted.
Mark
namtax
January 20, 2010, 2:43pm
3
Hi there, where would I ask the object what its id is? And how would I
do this?
Thanks
namtax
January 20, 2010, 4:33pm
5
Ok I am trying this as a test
any function save(event) output=false{
var rc = event.getCollection();
rc.user= taskService.getUser(event.getValue
("iUserID",""));
populateModel(rc.user);
userService.save(rc.user);
return rc.user;
}
And I am seeing the newly created entitys details being returned as an
array, but the id field is empty for some reason.....any ideas why?
Thanks for your time
namtax
January 20, 2010, 5:16pm
6
Update, sorry have managed to return the id field in the newly created
entity now...however when I now try this
any function save(event) output=false{
var rc = event.getCollection();
rc.user= taskService.getUser(event.getValue
("iUserID",""));
populateModel(rc.user);
userService.save(rc.user);
var id = rc.user.getId()
return id ;
}
I get the error message "Error casting an object of type
java.lang.Integer cannot be cast to java.lang.String to an
incompatible type."
Thanks
namtax
January 20, 2010, 5:36pm
7
Ok, update again, ha ha
Managed to get it working...
Many thanks for your help