Re: EditingContext problem, ghost entry in datastore [ was Debuging WOManyToManyRelationship]
Re: EditingContext problem, ghost entry in datastore [ was Debuging WOManyToManyRelationship]
- Subject: Re: EditingContext problem, ghost entry in datastore [ was Debuging WOManyToManyRelationship]
- From: Dev WO <email@hidden>
- Date: Tue, 2 Aug 2005 19:51:38 +0200
Hi Chuck,
sorry for the late reply, I wasn't sleeping, but I redo all my
component which had quite a few stuff in it...
So all your tip did the trick and I was able to correctly create and
discard the objects and everything is finally work fine with the M-to-
M relationship.
Basically, I made sure the object.ec.revert() was called every time I
wasn't needing the object and created the new ones using your:
object = (Object) EOUtilities.createAndInsertInstance
(session.defaultEditingContext(), "Object");
I'm not 100% sure I understand everything for now but it gets
clearer, slowly but surely;)
I'm going to dig a little more into the object graph stuff for sure...
So thanks again for all your help Chuck:)
An more to come;)
Xavier
On Jul 26, 2005, at 2:58 PM, Dev WO wrote:
Hi Chuck, and I'm really sorry about keeping on asking question
about this...
I think it is coming down to a design flaw in your page.
We're getting really closer, here's the latest "problem":
when I add or update, the product previously in the form is still
filling the textfields. Everything is ok on the database side.
Let's take a step back here. What do you want to happen in these
situations:
1. User goes to form to create new object. They click Save. What
do they see then?
2. User goes to form to edit existing object. They click Save.
What do they see then?
So I think the creation of an empty object isn't fully working:
here the setup:
-no creation of productGeneric Object on initialisation
-the addOrUpdate method is:
public WOComponent addOrUpdateProductGeneric()
{
awakeFromInsertionProductGeneric(ec);
ec.saveChanges();
return context().page();
}
-the awakeFromInsertionProductGeneric method is:
public void awakeFromInsertionProductGeneric (EOEditingContext
ec) {
if (productGeneric.datePosted() == null) {
productGeneric.setDatePosted(new NSTimestamp());
productGeneric.setEmployeePosted(session.employee());
productGeneric.setStockStatus(new Integer(0));
}
else {
productGeneric.setDateUpdated(new NSTimestamp());
productGeneric.setEmployeeUpdated(session.employee());
editMode = false; // to get back to adding mode
}
}
-I've added:
if (editMode) {
setProductToBeEdited(null);
}
to the appendToResponse method.
the append to response method to:
if (!editMode) {
setProductToBeEdited(null);
}
I don't understand that part. Maybe paste the whole method?
I've got an empty form after every "add",
That is for a new object. Is that right? Is that what you want?
and everything works fine in the database. But, there's a but;)
If I edit a previous productGeneric, I got a ghost inserted in the
database when "update" (and get an empty form to add another
product).
The ghost is caused by creating a object when you don't really need
to or not calling ec.revert() before you edit the existing object.
So here's my edit method:
public WOComponent editProductGeneric()
{
productGeneric = aProductGeneric;
if some method has already called productGeneric() then an empty
one will have been created. Probably that is the cause of your
ghost. If you want to learn more about this, add this line to
productGeneric():
NSLog.out.appendln(new RuntimeException("productGeneric called"));
This will print a stack trace for each call to productGeneric. Or,
wrap this in if (productGeneric == null) to only print a stack
trace when an new object is created. This will show you where the
call is coming from.
To work around this, try this:
aProductGeneric.editingContext().revert();
productGeneric = aProductGeneric;
editMode = true;
return context().page();
}
editMode is really only used to hide or display some part of the
page, there's nothing "intelligent" in it.
So it gets closer, but now the problem has moved from the "adding"
to the "update";)
I'm pretty lost in fact as I'm not sure to fully understand all
this;)
Thanks again for your valuable support Chuck:)
You are welcome. I think we are getting closer.
Chuck
Le 26 juil. 05 à 18:58, Chuck Hill a écrit :
I'm not sure what you don't understand. :-) This is the code I
meant:
public WOComponent addOrUpdateProductGeneric()
{
awakeFromInsertionProductGeneric(ec); //setting the date
posted/updated
if (!productGenericList.containsObject(productGeneric))
{
productGeneric.setStockStatus(new Integer(0));
}
else
{
editMode = false;
}
ec.saveChanges();
// If we just created a new object and saved it,
// reset object so that another new object will be created
// for next time
if (editMode) {
setProductToBeEdited(null);
}
return context().page();
}
Chuck
On Jul 23, 2005, at 9:20 AM, Dev WO wrote:
-----
public WOComponent addOrUpdateProductGeneric()
{
awakeFromInsertionProductGeneric(ec); //setting the
date posted/updated
if (!productGenericList.containsObject(productGeneric))
{
productGeneric.setStockStatus(new Integer(0));
}
else
{
editMode = false;
}
ec.saveChanges();
Replace the code below with something like:
// We just created a new object and saved it.
// Reset page so that another new object will be created
if (editMode) {
setProductToBeEdited(null);
}
productGeneric = new ProductGeneric();
ec.insertObject(productGeneric);
productGeneric.setCommentaryAllowed(new Boolean(true));
productGeneric.setIsAvailable(new Boolean(true));
productGeneric.setSalesPrice(new Integer(0));
return context().page();
}
--
Practical WebObjects - a book for intermediate WebObjects
developers who want to increase their overall knowledge of
WebObjects, or those who are trying to solve specific application
development problems.
http://www.global-village.net/products/practical_webobjects
--
Practical WebObjects - a book for intermediate WebObjects
developers who want to increase their overall knowledge of
WebObjects, or those who are trying to solve specific application
development problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden