• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Infinite Loop in Editing Context
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Infinite Loop in Editing Context


  • Subject: Infinite Loop in Editing Context
  • From: Bobbie Daniels <email@hidden>
  • Date: Thu, 22 Jan 2004 14:26:13 -0500

List,

I need to add a row to the database when a user edits or updates certain
fields in the application.  From this, I will generate a report showing the
edited or updated fields. The method is saving the updates and adding a row,
but it is in an infinite loop, so instead of getting only one row, I get
many, many rows.  Does anyone have any idea why this method keeps getting
called?  This is a Direct to Java Client Application, using EOS and a Custom
Controller.

**This is the code in the client side of the entity.

public Object appendActivityLog(NSDictionary args) {
        return invokeRemoteMethod("clientSideRequestAppendActivityLog", new
Class[] {NSDictionary.class}, new Object[] {args});
    }


**This is the code in the server side of the entity.

public Object clientSideRequestAppendActivityLog(NSDictionary args) {
        return appendActivityLog(args);
    }

    public Object appendActivityLog(NSDictionary args) {
        EOEditingContext ec = editingContext();
        try {
            //Create the ActivityLog and initalize here
            ActivityLog newLog =
(ActivityLog)EOUtilities.createAndInsertInstance(ec, "ActivityLog");
            newLog.appendln(args);
            ec.saveChanges();
        }
        catch(Exception ex) {
            NSLog.out.appendln("Failed to save ActivityLog: " +
ex.getMessage());
        }
        return null;
    }


**This is the code in the Custom Controller.

public class CustomClaimantFormController extends EOFormController {

    public CustomClaimantFormController(EOXMLUnarchiver unarchiver) {
        super(unarchiver);
        NSNotificationCenter nc = NSNotificationCenter.defaultCenter();
        nc.addObserver(this, new NSSelector("logUserChanges", new Class[] {
NSNotification.class}),
EOEditingContext.EditingContextDidSaveChangesNotification,
editingContext());
    }

    public void logUserChanges(NSNotification notification) {
        //Get the EditingContext from the Notification
        EOEditingContext ec = (EOEditingContext)notification.object();
        //Create a nested editing context
        EOEditingContext localEC = new EOEditingContext();
        //Append to the ActivityLog here
        EOGlobalID personGID =
AuthenticationCenter.sharedAuthenticationCenter().userGlobalID();
        User user = (User)(localEC.faultForGlobalID(personGID, ec));
        EOGlobalID claimantGID = ec.globalIDForObject(selectedObject());
        Claimant claimant = (Claimant)localEC.faultForGlobalID(claimantGID,
ec);
        NSMutableDictionary args = new NSMutableDictionary();
        args.setObjectForKey(user, "user");
        args.setObjectForKey(claimant, "claimant");
        args.setObjectForKey(claimant.amount(), "amount");
        claimant.appendActivityLog(args);
        localEC.saveChanges();
    }
}
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Infinite Loop in Editing Context
      • From: Chuck Hill <email@hidden>
  • Prev by Date: Re: WebObjects Blog
  • Next by Date: Re: WebObjects Blog
  • Previous by thread: Re: WebObjects Blog
  • Next by thread: Re: Infinite Loop in Editing Context
  • Index(es):
    • Date
    • Thread