3 Replies Latest reply on Mar 28, 2011 9:21 AM by BosDog

    how to send flex datagrid provider to coldfusion remoteobject

    BosDog Level 1

      i can bind the results from the coldfusion remoteobject to the dataprovider in the flex grid no problem. but i allow the user to alter the contents of the datagrid (by altering the dataprovider data) and then want them to be able to click a save button when they are finished. this should send the dataprovider for the grid over to the coldfusion remote object and then loop over the length of the dataprovider to insert rows into a database based on the number of rows in the datagrid.

       

      in the past ive done this by saving the values each time the user changes the datagrid. the problem is i dont want anything to save UNTIL the user specifically clicks the save button in the app.

        • 1. Re: how to send flex datagrid provider to coldfusion remoteobject
          Codeflayer Level 1

          Typically this would be done with an MVC architecture. You should have a service from your server to get the data for the dataprovider as well as a service to update the data once it's been modified.

           

          Here's a really basic breakdown:

           

          Getter service should populate a model object on the client.

           

          The datagrid is bound to the model to display the data.

           

          Edits in the datagrid should be propegated to the model.

           

          once the user hits the submit button, the model object should be sent to a setter service on the server

           

          Setter service updates the database.

           

          It sounds like you currently update the database directly from your flex app which is why it might be troublesome for you to get the effect you want.

          • 2. Re: how to send flex datagrid provider to coldfusion remoteobject
            BosDog Level 1

            i've setup a bindable object that links to the datagrid dataprovider. when i pass it into CF as an object what is the syntax i need to loop over the object and insert into the db? or do i need to convert the dataprovider of the grid to an arraycollection of do something else or is leaving it as an object ok?

            • 3. Re: how to send flex datagrid provider to coldfusion remoteobject
              BosDog Level 1

              nevermind i figured it out... for anyone else looking to do this you can pass the dataprovider directly to the CF remoteobject by setting up an OBJECT variable in actionscript = the dataprovider name. coldfusion treats this as an array with structs in it.

               

              then in CF when you pass that actionscript object over you can loop over it like an array and reference the column names (mine was called agreementObject):

               

              <cfloop from="1" to="#ArrayLen(agreementObject)#" index="i">

                          <cfquery name="ins" datasource="#dbLink#">
                          insert into agreements
                          values(
                          '#agreementObject[i].ITEM_TYPE#',
                          to_date('#DateFormat(agreementObject[i].AGREE_DATE,"mm/dd/yyyy")#','mm/dd/yyyy')
                          )
                          </cfquery>

              </cfloop