2 Replies Latest reply on Jun 16, 2011 9:18 AM by pjlumby

    DataService reading but not writing

    pjlumby

      I have set up some basic CRUD services, the reading part works fine but create, update and delete dont' seem to do a bean. I have been using the network monitor to see what is happening and can see my read services woking fine but the others dont do a thing when called.

       

      <fx:Declarations>

      <customcategoryservice:CustomcategoryService id="customcategoryService"
                    fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
                    showBusyCursor="true"/>
      <s:CallResponder id="createCustom_categoryResult"/>
      <s:CallResponder id="getCustom_categoryByAuthorIDResult2" result="getCustom_categoryByAuthorIDResult2_resultHandler(event)"/>
      <s:CallResponder id="updateCustom_categoryResult" result="updateCustom_categoryResult_resultHandler(event)"/>
      <s:CallResponder id="deleteCustom_categoryResult" result="deleteCustom_categoryResult_resultHandler(event)"/>

      </fx:Declarations>

       

      <fx:Script>

       

      protected function cat_dg_creationCompleteHandler(event:FlexEvent):void
         {
          getCustom_categoryByAuthorIDResult2.token = customcategoryService.getCustom_categoryByAuthorID(current_user, image_target);
         }
        
         protected function getCustom_categoryByAuthorIDResult2_resultHandler(event:ResultEvent):void
         {
          // TODO Auto-generated method stub
          arr_custom_categories = event.result as ArrayCollection;
         }
         
         protected function update_button_clickHandler(item:Custom_category):void
         {
          updateCustom_categoryResult.token = customcategoryService.updateCustom_category(item);
         }
         
         protected function delete_button_clickHandler(itemID:int):void
         {
          deleteCustom_categoryResult.token = customcategoryService.deleteCustom_category(itemID);
         }
        
         protected function createCustom_categoryResult_resultHandler(event:ResultEvent):void
         {
          arr_custom_categories.addItem(event.result);
          custom_category = event.result as Custom_category;
          cat_dg.scrollToIndex(arr_custom_categories.length);
         }
         protected function updateCustom_categoryResult_resultHandler(event:ResultEvent):void
         {
          trace('Updated successfully');
         }
        
         protected function deleteCustom_categoryResult_resultHandler(event:ResultEvent):void
         {
          arr_custom_categories.removeItemAt(cat_dg.selectedIndex);
         }

       

      </fx:Script>

       

      The services work fine when I use the sevices test operation in flash builder, just nothing when testing on the build.

       

      Pete

       

       

        • 1. Re: DataService reading but not writing
          paula_ke Level 1

          I'm having exactly the same problem (see http://forums.adobe.com/thread/863061).  Can read, can see read network traffic, cannot write, Do not see any network traffic.

           

          Either there is a real bug here or we both have the same, very wrong, configuration parameter somewhere.

           

          Anyone out there that has seen this and solved it?  Adobe? Zend?

          • 2. Re: DataService reading but not writing
            pjlumby Level 1

            Ok, I've got a workaround.

             

            It involves hacking the generated _Super_NameService.as which I realise isn't ideal. I've included relevant section below with all the changes commented out.

             

             

            /**
            * This is a generated class and is not intended for modification.  To customize behavior
            * of this service wrapper you may modify the generated sub-class of this class - SubjectService1.as.
            */
            package services.subjectservice1
            {
            import com.adobe.fiber.core.model_internal;
            import com.adobe.fiber.services.wrapper.RemoteObjectServiceWrapper;
            //import com.adobe.fiber.valueobjects.IValueObject;
            import com.adobe.serializers.utility.TypeUtility;
            //import mx.collections.ListCollectionView;
            //import mx.data.DataManager;
            //import mx.data.IManaged;
            //import mx.data.ItemReference;
            //import mx.data.ManagedAssociation;
            //import mx.data.ManagedOperation;
            //import mx.data.ManagedQuery;
            //import mx.data.RPCDataManager;
            //import mx.data.errors.DataServiceError;
            import mx.rpc.AbstractOperation;
            import mx.rpc.AsyncToken;
            import mx.rpc.remoting.Operation;
            import mx.rpc.remoting.RemoteObject;
            import valueObjects.Subject;

            import mx.collections.ItemResponder;
            import com.adobe.fiber.valueobjects.AvailablePropertyIterator;

            [ExcludeClass]
            internal class _Super_SubjectService1 extends com.adobe.fiber.services.wrapper.RemoteObjectServiceWrapper
            {
            //    private var _subjectRPCDataManager : mx.data.RPCDataManager;
            //    private var managersArray : Array = new Array();
            //
            //    public const DATA_MANAGER_SUBJECT : String = "Subject";
            //
            //    public function getDataManager(dataManagerName:String) : mx.data.RPCDataManager
            //    {
            //        switch (dataManagerName)
            //        {
            //             case (DATA_MANAGER_SUBJECT):
            //                return _subjectRPCDataManager;
            //            default:
            //                return null;
            //        }
            //    }
            //
            //    /**
            //     * Commit all of the pending changes for this DataService, as well as all of the pending changes of all DataServices
            //     * sharing the same DataStore.  By default, a DataService shares the same DataStore with other DataServices if they have
            //     * managed association properties and share the same set of channels.
            //     *
            //     * @see mx.data.DataManager
            //     * @see mx.data.DataStore
            //     *
            //     * @param itemsOrCollections:Array This is an optional parameter which defaults to null when
            //     *  you want to commit all pending changes.  If you want to commit a subset of the pending
            //     *  changes use this argument to specify a list of managed ListCollectionView instances
            //     *  and/or managed items.  ListCollectionView objects are most typically ArrayCollections
            //     *  you have provided to your fill method.  The items appropriate for this method are
            //     *  any managed version of the item.  These are any items you retrieve from getItem, createItem
            //     *  or using the getItemAt method from a managed collection.  Only changes for the
            //     *  items defined by any of the values in this array will be committed.
            //     *
            //     * @param cascadeCommit if true, also commit changes made to any associated
            //     *  items supplied in this list.
            //     *
            //     *  @return AsyncToken that is returned in <code>call</code> property of
            //     *  either the <code>ResultEvent.RESULT</code> or in the
            //     *  <code>FaultEvent.FAULT</code>.
            //     *  Custom data can be attached to this object and inspected later
            //     *  during the event handling phase.  If no changes have been made
            //     *  to the relevant items, null is returned instead of an AsyncToken.
            //     */
            //    public function commit(itemsOrCollections:Array=null, cascadeCommit:Boolean=false):mx.rpc.AsyncToken
            //    {
            //        return _subjectRPCDataManager.dataStore.commit(itemsOrCollections, cascadeCommit);
            //    }
            //
            //    /**
            //     * Reverts all pending (uncommitted) changes for this DataService, as well as all of the pending changes of all DataServics
            //     * sharing the same DataStore.  By default, a DataService shares the same DataStore with other DataServices if they have
            //     * managed association properties and share the same set of channels.
            //     *
            //     * In case you specify a value for itemsOrCollections:Array parameter, only pending (uncommitted) changes for the specified
            //     * managed items or collections will be reverted.
            //     *
            //     * @see mx.data.DataManager
            //     * @see mx.data.DataStore
            //     *
            //     * @param itemsOrCollections:Array This is an optional parameter which defaults to null
            //     * when you want to revert all pending (uncommitted) changes for all DataServices
            //     * managed by this DataStore. If you want to revert a subset of the pending changes use
            //     * this argument to specify a array of managed items or collections
            //     *
            //     * @return true if any changes were reverted.
            //     * @throws DataServiceError if the passed in array contains non-managed items or collections
            //     * 
            //     */
            //    public function revertChanges(itemsOrCollections:Array=null):Boolean
            //    {
            //        if (itemsOrCollections == null)
            //        {
            //            // Revert all changes
            //            return _subjectRPCDataManager.dataStore.revertChanges();
            //        }
            //        else
            //        {
            //            // Revert passed in items
            //            var anyChangeItemReverted:Boolean = false;
            //
            //            // Iterate over array and revert managed item or collection as the case may be
            //            for each (var changeItem:Object in itemsOrCollections)
            //            {
            //                if (changeItem is com.adobe.fiber.valueobjects.IValueObject)
            //                {
            //                    var dataMgr:mx.data.DataManager = getDataManager(changeItem._model.getEntityName());
            //                    anyChangeItemReverted ||= dataMgr.revertChanges(mx.data.IManaged(changeItem))
            //                }
            //                else if (changeItem is mx.collections.ListCollectionView)
            //                {
            //                    anyChangeItemReverted ||= _subjectRPCDataManager.dataStore.revertChangesForCollection(mx.collections.ListCollection View(changeItem));
            //                }
            //                else
            //                {
            //                    throw new mx.data.errors.DataServiceError("revertChanges called on array that contains non-managed items or collections");
            //                }
            //            }
            //            return anyChangeItemReverted;
            //        }
            //    }

                // Constructor
                public function _Super_SubjectService1()
                {
                    // initialize service control
                    _serviceControl = new mx.rpc.remoting.RemoteObject();

                    // initialize RemoteClass alias for all entities returned by functions of this service
                    valueObjects.Subject._initRemoteClassAlias();

                    var operations:Object = new Object();
                    var operation:mx.rpc.remoting.Operation;

                    operation = new mx.rpc.remoting.Operation(null, "getAllSubject");
                     operation.resultElementType = valueObjects.Subject;
                    operations["getAllSubject"] = operation;
                    operation = new mx.rpc.remoting.Operation(null, "getSubjectByID");
                     operation.resultType = valueObjects.Subject;
                    operations["getSubjectByID"] = operation;
                    operation = new mx.rpc.remoting.Operation(null, "createSubject");
                     operation.resultType = int;
                    operations["createSubject"] = operation;
                    operation = new mx.rpc.remoting.Operation(null, "updateSubject");
                    operations["updateSubject"] = operation;
                    operation = new mx.rpc.remoting.Operation(null, "deleteSubject");
                    operations["deleteSubject"] = operation;
                    operation = new mx.rpc.remoting.Operation(null, "count");
                     operation.resultType = int;
                    operations["count"] = operation;
                    operation = new mx.rpc.remoting.Operation(null, "getSubject_paged");
                     operation.resultElementType = valueObjects.Subject;
                    operations["getSubject_paged"] = operation;

                    _serviceControl.operations = operations;
                    _serviceControl.convertResultHandler = com.adobe.serializers.utility.TypeUtility.convertResultHandler;
                    _serviceControl.source = "SubjectService1";
                    _serviceControl.endpoint = "gateway.php";
            //        var managedAssociation : mx.data.ManagedAssociation;
            //        var managedAssocsArray : Array;
            //        // initialize Subject data manager
            //        _subjectRPCDataManager = new mx.data.RPCDataManager();
            //        managersArray.push(_subjectRPCDataManager);
            //
            //        managedAssocsArray = new Array();
            //
            //        _subjectRPCDataManager.destination = "subjectRPCDataManager";
            //        _subjectRPCDataManager.service = _serviceControl;       
            //        _subjectRPCDataManager.identities =  "subject_id";     
            //        _subjectRPCDataManager.itemClass = valueObjects.Subject;
            //
            //
            //
            //        var dmOperation : mx.data.ManagedOperation;
            //        var dmQuery : mx.data.ManagedQuery;
            //
            //        dmQuery = new mx.data.ManagedQuery("getAllSubject");
            //        dmQuery.propertySpecifier = "subject_id,subject_name,organisation_id,active_for_raptor,postcard_subject_name,descript ion_text,master_subject";
            //        dmQuery.parameters = "";
            //        _subjectRPCDataManager.addManagedOperation(dmQuery);
            //
            //        dmOperation = new mx.data.ManagedOperation("createSubject", "create");
            //        dmOperation.parameters = "item";
            //        _subjectRPCDataManager.addManagedOperation(dmOperation);    
            //
            //        dmOperation = new mx.data.ManagedOperation("deleteSubject", "delete");
            //        dmOperation.parameters = "id";
            //        _subjectRPCDataManager.addManagedOperation(dmOperation);    
            //
            //        dmOperation = new mx.data.ManagedOperation("updateSubject", "update");
            //        dmOperation.parameters = "item";
            //        _subjectRPCDataManager.addManagedOperation(dmOperation);    
            //
            //        dmOperation = new mx.data.ManagedOperation("getSubjectByID", "get");
            //        dmOperation.parameters = "subject_id";
            //        _subjectRPCDataManager.addManagedOperation(dmOperation);    
            //
            //        dmQuery = new mx.data.ManagedQuery("getSubject_paged");
            //        dmQuery.propertySpecifier = "subject_id,subject_name,organisation_id,active_for_raptor,postcard_subject_name,descript ion_text,master_subject";
            //        dmQuery.countOperation = "count";
            //        dmQuery.pagingEnabled = true;
            //        dmQuery.positionalPagingParameters = true;
            //        dmQuery.parameters = "startIndex,numItems";
            //        _subjectRPCDataManager.addManagedOperation(dmQuery);
            //
            //        _serviceControl.managers = managersArray;

                     preInitializeService();
                     model_internal::initialize();
                }
               
                //init initialization routine here, child class to override
                protected function preInitializeService():void
                {
                    destination = "SubjectService1";
                 
                }
             

                /**
                  * This method is a generated wrapper used to call the 'getAllSubject' operation. It returns an mx.rpc.AsyncToken whose
                  * result property will be populated with the result of the operation when the server response is received.
                  * To use this result from MXML code, define a CallResponder component and assign its token property to this method's return value.
                  * You can then bind to CallResponder.lastResult or listen for the CallResponder.result or fault events.
                  *
                  * @see mx.rpc.AsyncToken
                  * @see mx.rpc.CallResponder
                  *
                  * @return an mx.rpc.AsyncToken whose result property will be populated with the result of the operation when the server response is received.
                  */
                public function getAllSubject() : mx.rpc.AsyncToken
                {
                    var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("getAllSubject");
              var _internal_token:mx.rpc.AsyncToken = _internal_operation.send() ;
                    return _internal_token;
                }
                
                /**
                  * This method is a generated wrapper used to call the 'getSubjectByID' operation. It returns an mx.data.ItemReference whose
                  * result property will be populated with the result of the operation when the server response is received.
                  * To use this result from MXML code, define a CallResponder component and assign its token property to this method's return value.
                  * You can then bind to CallResponder.lastResult or listen for the CallResponder.result or fault events.
                  *
                  * @see mx.data.ItemReference
                  * @see mx.rpc.CallResponder
                  *
                  * @return an mx.data.ItemReference whose result property will be populated with the result of the operation when the server response is received.
                  */
                public function getSubjectByID(itemID:int) : mx.rpc.AsyncToken // mx.data.ItemReference
                {
                    var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("getSubjectByID");
              var _internal_token:mx.rpc.AsyncToken /*mx.data.ItemReference*/ = _internal_operation.send(itemID);//as mx.data.ItemReference;
                    return _internal_token;
                }

             

             

            Hope this helps.

             

            Message was edited by: pjlumby Warning!! If you add new services the changes are laible to be lost so if you've got it working, back it up.