2
votes

I have a NavigatorContent which is displayed when the user selects an item in a DataGrid. This NavigatorContent contains a form and an accordion displaying the related objects.

When the user presses the Save button in the NavigatorContent the form and the children should be saved to the database by calling the server through BlazeDS:

saveObjectToDB()
{
  //Map the form values to the object
  object.field1 = object_field1.text;
  object.field2 = object_field2.selectedDate as Date;
  object.relatedobject3 = comboBox.selectedItem as RelatedObject3;
  //etc.....

  //Loop through accordion to save the child objects
  for(var i:int= 0; i < accordion.numChildren; i++ )
  {
    if(accordion.getChild(i) is RelatedObject1Form)
    {
      var formRelated1:RelatedObject1Form = accordion.getChild(i) as RelatedObject1Form;
      //Map the form values to the related object
      object.relatedobject1.field1 = formRelated1.relatedobject1_field1.selectedDate;
      //etc...
    }
    if(accordion.getChild(i) is RelatedObject2Grid)
    {
      var gridRelated2:RelatedObject2Grid = accordion.getChild(i) as RelatedObject2Grid;
      //Get dataProvider for the datagrid of the relatedObject
      object.relatedobject2 = gridRelated2.object.relatedobject2;
    }
  }

  // Call the remoting object's saveObject method
  var saveObjectOperation:Operation = new Operation();
  saveObjectOperation.name = "saveObject";
  saveObjectOperation.arguments=[object];
  ro.operations = [saveObjectOperation];
  saveObjectOperation.send();

  if(isNewObject)
    //dispatchEvent new object
  else
    //dispatchEvent object updated
}

My problem is as the question states that my application freezes for a few seconds when the user presses the save button that calls this method. I guess that is because Flex is single threaded, but still i dont quite get why this method would be so computational expensive? It doesnt seem to matter if i comment out the loop that loops over the accordion children.

I tried setting the objects related objects to null before calling the remote save method, and this seemed to speed up the save method, but it provided me with some troubles later.

My conclusion is that the remote call is whats freezing up the application, and if i set the related objects to null this seems to fix the issue. But is this really necessary? The related objects aren't really that big, so i don't quite get why the remote call should freeze the application for a few seconds.

This is how i create the accordion children when the NavaigatorContent is intialized:

    var relatedObjectForm:RelatedObject1Form= new RelatedObject1Form();
    accordion.addChild(relatedObjectForm);
    relatedObjectForm.object= object;
    relatedObjectForm.ro = this.ro;

The object that i pass to the accordion children is public and [Bindable] in the NavigatorContent and in the accordion children and is initially passed from the main DataGrid. May this be a problem relating to this issue?

Any help/comments is much appreciated. This issue is starting to affect my beauty sleep ;)

1
Anyone had any experience with this kind of problem before? =) - Sebastian

1 Answers

2
votes

My guess would be that you're spending a lot of time in the serializer. Put a trace target in the app and watch the console when it runs to see what's being sent.

The most likely problems are from DisplayObjects - if they've been added to the application they will have a reference to the application itself, and will cause some serializers to start serializing the entire app. The bindable object might have some odd events attached that eventually attach to DisplayObjects - try copying the relevant values in it into your object instead of just taking a reference to the existing object.