Silverlight Object is still being edited and cannot be saved

Silverlight Object is still being edited and cannot be saved

Old forum URL: forums.lhotka.net/forums/t/8652.aspx


Eblanchette posted on Friday, March 12, 2010

Hello,

I have a EditableRootList bound to a datagrid.  When I try to save the list, I get the error "Object is still being edited and cannot be saved".  I tried calling datagrid.CommitEdit(), and List.ApplyEdit(), but nothing seems to work.  I would like some advice on that.

currentTrips.BeginSave((o, z) =>

            {

                if (z.Error == null)

                {

                    currentTrips = (TripERList)z.NewObject;

                    CreateLoadTrips();

                }

                else

                {

                    throw z.Error;

                }

            });

 

Thank you!

Eblanchette replied on Friday, March 12, 2010

I found this in the BeginSave method of the framework:

     else if (EditLevel > 0)

      {

        Validation.ValidationException error = new Validation.ValidationException(Resources.NoSaveEditingException);

        if (handler != null)

          handler(this, new SavedEventArgs(null, error, userState));

        OnSaved(null, error, userState);

      }

      else if (!IsValid)

      {

        Validation.ValidationException error = new Validation.ValidationException(Resources.NoSaveEditingException);  Should'nt this be "NoSaveInvalidException" ??

        if (handler != null)

          handler(this, new SavedEventArgs(null, error, userState));

        OnSaved(null, error, userState);

      }

RockfordLhotka replied on Friday, March 12, 2010

Every BeginEdit() call needs to have a matching ApplyEdit() call on that specific object.

When using in-place editing in a datagrid control, the datagrid is responsible for using the IEditableObject interface to call begin/end/cancel edit on each row as the user enters and leaves that row.

I know there are issues with the WPF datagrid not working correctly - hopefully they'll get up to speed for WPF 4.

But the SL datagrid has been working well since SL3. Actually there was a fixed datagrid for SL2 too, but the original one didn't work quite right.

However, it could be an issue where the user is in a row of the datagrid, and then clicks a button elsewhere on the form, thus technically shifting the focus out of the datagrid - but in that case perhaps the datagrid isn't detecting that the user left the row, and so isn't committing that row with an IEditableObject.EndEdit() call?

Eblanchette replied on Saturday, March 13, 2010

Thank you for the information,

I found out that when my object had validationExceptions, it fires the "object is still being edited" message.  Maybe it's a mistake in the csla code as my previous post mentioned?

RockfordLhotka replied on Saturday, March 13, 2010

Yes, that was a bug - you must not be running current code, as I believe that bug was found and fixed some time ago.

Eblanchette replied on Monday, March 15, 2010

I am currently running csla 3.8.3, but I will double-check my project just to be sure the bug is not in this version.  Thank you!

JasonBJones replied on Thursday, May 13, 2010

I am also running csla 3.8.3 and ran into this issue.  I tracked it down to one value being put into a dataset. When I commented that one line out, I no longer received the object is busy error. The below is an copy of my code.

 _Cov.BeginEdit()
        _Cov.CarrierID = opt.CarrierId
        _Cov.CoverageTypeID = opt.CoverageTypeId

'_Cov.Covereage = opt.Coverage
        _Cov.CarrierName = opt.Carrier
        _Cov.UpdatePlanUponSaving = True
        _Cov.ApplyEdit()

 

The _cov object  Inherits BusinessBase(Of T)

 

P.S. I am new to Silverlight and CSLA and would like to add that I have found your videos and this forum very  helpful.

ninoarena replied on Thursday, May 13, 2010

I noticed this behaviour too whenever I get a validation error on my telerik RadGridView control.  This error actually motivated me to find out why the error message I put into my business object validation rule is not showing up instead of this 'Object is still being edited and cannot be saved' message.

ninoarena replied on Thursday, May 13, 2010

I forgot to mention that I am still in the process of trying to resolve this issue I am encountering, wherein I can't get my error message to show up when the validation failed.  I'll post my findings when I find the answer.

Thanks.

JasonBJones replied on Thursday, May 13, 2010

I do remember reading a post made by Rockford, don't recall which one, that stated this was a bug and he had fixed it in the C# version and was going to bring it to the VB version.  I am using VB.  Maybe the fix never made it to the VB side?

ninoarena replied on Thursday, May 13, 2010

I am using C#.  I am thinking this is not a bug but me not knowing how to use this business rule/PropertyStatus control.  I was just hoping there will be an example out there for CSLA 4, Silverlight 4, MVVM, simple CRUD application.

RockfordLhotka replied on Thursday, May 13, 2010

Busy and being edited are two different things. I'll assume we're talking about the object being edited?

This exception occurs because of a mismatch between calls to BeginEdit and either CancelEdit or ApplyEdit. Every BeginEdit call must have a matching Cancel/Apply call.

Some complex controls (usually datagrid controls) don't follow the rules at all times, and don't always call the cancel/apply method like they are supposed to. That's a bug in the control. Sometimes you can overcome it by handling events at the UI layer, sometimes you need to get the control vendor to fix the control.

Almost always, they are invoking the methods through the IEditableObject interface - that's what they should be doing anyway. And there too, there should be symmetry between the begin and cancel/end edit calls.

JasonBJones replied on Friday, May 14, 2010

OK I believe I have found the issue here.  For starters I do have the proper levels of beginedit and applyedits.  This issue was in my validation.  I had one rule that was not returning an error value. Notice the code below the last line has return true. This was not orginally there.  my brokenrules validation had an error with this field with severity of ERROR and no description.  After adding the return true it now works fine.  So the error is my fault for not having proper error handling but CSLA is also returning a odd error.  Just my two cents.

 

 

 

 

 

 

 

 

 

Private Shared Function IsPlanName(ByVal target As SubscriberCoverage, ByVal e As RuleArgs) As Boolean

 

 

If target.GetProperty(CoverageTypeProperty) = "PPO" Then

e.Description =

"PCP - Primary Care Physician."

e.Severity = RuleSeverity.Information

 

 

Return False

 

 

End If

 

 

Return True

 

 

End

Function

RockfordLhotka replied on Friday, May 14, 2010

The compiler should have at least warned you (but I think the default is error?) about not explicitly returning a value from the function. Oh, I think VB is only a warning though, so it would compile. You can configure the compiler to make that an error so VB won't compile functions that don't return a value on all paths.

JasonBJones replied on Friday, May 14, 2010

One more note on this is that this only seems to happen when I am adding a record. If the record already existed the save would happen just fine.  I hope this helps you out.

RockfordLhotka replied on Friday, May 14, 2010

What version of CSLA are you using Jason? There was a bug in some older versions where the wrong exception text was returned for an invalid object - I wonder if you are hitting that problem.

To be savable, an object must be not in edit mode, valid, not busy and the user authorized. The IsValid check threw an exception, but with the wrong text description.

JasonBJones replied on Friday, May 14, 2010

I have version 3.8.2.  I have made one change to the code but it was only to make the edit level public.  This was done in an attempt to isolate this problem.  Thanks again for you quick and helpful responses, I have only been using Silverlight and CSLA now for 3 months but you have made this transition much easier, I came from a primarily desktop background and largely VB 6. So you can imagine the struggle I am having.

Copyright (c) Marimer LLC