umarbeyoglu
umarbeyoglu

Reputation: 450

XAF - How to keep NonPersistent Objects inside Persistent BusinessObject

BusinessObject :

    public partial class LG_124_01_QPRODUCT : XPLiteObject
    {

      List<altMamüller> faltMalzemeler;
      [NonPersistent]
      public List<altMamüller> altMalzemeler
      {
          get { return faltMalzemeler; }
          set { SetPropertyValue<List<altMamüller>>(nameof(altMalzemeler), ref faltMalzemeler, value); }
      }

   public LG_124_01_QPRODUCT()
   {
    altMalzemeler = new List<altMamüller>();
   }

    }

Here is what I want to do. I use a view controller to add items to my list inside the businessobject shown above. After I add it, I want to refresh the view so that user can see changes made.

But the problem is that when view is refreshed, the object is disposed so I can't reach it:

     task = (LG_124_01_QPRODUCT)View.CurrentObject;
    task.altMalzemeler = new List<altMamüller>();
    foreach (altMamüller note in e.PopupWindowViewSelectedObjects)
    {
        task.altMalzemeler.Add(note);
    }
    View.Refresh();

Here is the error I get:

Cannot access a disposed object.
Object name: 'AppName.Module.BusinessObjects.Database.altMamüller(855)'.

-2nd method that I have tried is using globalvariables. I have planned to assign the chosen objects from PopUpWindow to a global variable and then when the view is refreshed , I could add the chosen objects to the businessobject through the constructor. But then I learned C# has no globalvariable (I may be wrong if there is an alternative way)

-3rd method that I have tried is to add another PopupWindow after the refresh button. Here is the code

            showNotesAction.CustomizePopupWindowParams += ShowNotesAction_CustomizePopupWindowParams2;
---------------------
        private void ShowNotesAction_CustomizePopupWindowParams2(
                object sender, CustomizePopupWindowParamsEventArgs e)
        {
            IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(LG_124_01_QPRODUCT));
            Object currentObject = objectSpace.GetObject(View.CurrentObject);
            if (currentObject != null)
            {
                e.View = Application.CreateDetailView(objectSpace, currentObject);
            }
            else
            {
                objectSpace.Dispose();
            }
        }

When I try 3rd method,I get this error:

Value cannot be null. (Parameter 'args.View cannot be null. Initialize args.View with a ListView, DetailView or DashboardView created using the XafApplication.CreateXXXView methods.)

Then lastly , 4th method I have used is to put the items into Listview inside ViewController rather than Detailview but I do not know how to manipulate Listview's CollectionSource. Here is the incomplete code:

        private void ShowNotesAction_CustomizePopupWindowParams3(object sender, CustomizePopupWindowParamsEventArgs e)
        {
            View.Refresh();
            IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(LG_124_01_QPRODUCT));
            Object currentObject = objectSpace.GetObject(View.CurrentObject);

            IMemberInfo memberinfo = Application.TypesInfo.FindTypeInfo(typeof(altMamüller)).FindMember("Tasks");
            string viewId = ModelNestedListViewNodesGeneratorHelper.GetNestedListViewId(memberinfo);
            PropertyCollectionSource collectionSource = Application.CreatePropertyCollectionSource(ObjectSpace, typeof(altMamüller), View.CurrentObject, memberinfo, viewId, CollectionSourceDataAccessMode.Server, CollectionSourceMode.Normal);


            if (currentObject != null)
            {
               e.View = Application.CreateListView(viewId, collectionSource, false);
            }
            else
            {
                objectSpace.Dispose();
            }
        }

So about the solutions, is there anyone that can help me about one of these 4 methods:

1-How to use non-persistent objects after disposal?

2-How to manipulate globalvariables such that I can assign them in businessobjects constructor

3-How to solve the null issue

4-How to manipulate collectionsource in such way that I can show these list of items

or any other solution to reassign non-persistent items to a persistent object after disposal?

Upvotes: 0

Views: 38

Answers (0)

Related Questions