9 Replies Latest reply on Apr 23, 2009 2:09 PM by Michael Borbor

    Using an Object to get datagrid record properties? (update record)

    EvolvedDSM Level 2

      I have a datagrid that uses a set of data gathered from a remoteObject CFC.  The datagrid populates the result of the remoteObject method.  I then need the ability to edit records within the datagrid.  I have created a form that binds it's fields to the record properties of the selected item in the datagrid. So when a user clicks a record from the datagrid, the form fields populate with the appropriate data.  At this point, if they need to change any of the values, they can type their corrections.  There's a submit button that calls the update function updateRecord().  From here I'd like to stick all the values from the fields into an Object that has the structure of my data.  This is where I'm stuck.

       

      private function updateRecord(){

           var objNew:Object = new Object; // I want to store my updated values here

           var objOld:Object = new Object; // current values from the datagrid are stored here

           objNew = datagrid.selectedItem; // attempting to store and structure the values of the record from the datagrid

           objNew.firstName = firstNameInput.text; // firstName is a column of my data set

           objNew.lastName = lastNameInput.text; // lastName is also a column of my data set

           objOld = datagrid.selectedItem; // attempting to store the structure and values of the record from the datagrid

           remoteObject.update(objOld, objNew); // method that grabs the old object and new object and updates the record in the database

      }

       

      At this point I would assume that when I set my objNew Object to datagrid.selectedItem, it contains both the structure of the record as well as it's values.  But when I update the record, it fails because the structure is not what the CFC is expecting (it checks the structure against a valueObject that contains the properties and data types of the record).

       

      So how can I get an object to take on the structure of my data and then modify the individual properties of the object so I can make changes to my record?

        • 1. Re: Using an Object to get datagrid record properties? (update record)
          Michael Borbor Level 4

          Hi there I think that what you need to do is not declare objNew as an object but as the dto or vo that is use to pass data and get data fro CF

          • 2. Re: Using an Object to get datagrid record properties? (update record)
            EvolvedDSM Level 2

            Well, I have tried using the VO and that works fine.  The problem is that not all data properties are available to edit via the form fields, so if I use the VO, I have to specify every property in my function even if they aren't being edited.

             

            For example, lets set my data contains a firstName, lastName, email, and phone property (or column in the db table).  I do not want the email and phone to be upated, only the firstName and lastName properties.  Yet in my function, for the VO to work, I would have to do this...

             

            myVO = new valueObject; // valueObject.as contains the data structure

            myVO.firstName = firstNameInput.text;

            myVO.lastName = lastNameInput.text;

            myVO.email = datagrid.selectedItem.email;

            myVO.phone = datagrid.selectedItem.phone;

             

            The reason I have to do this is because the VO will submit null/blank values as default if I do not specify other data to those properties (in this case email and phone).  If I exclude email and phone from myVO above, it will delete any value I might have had previously when the remoteObject method updates with my given data.

             

            I oringally thought I could do myVO = datagrid.selectedItem, however it will not accept this because my type valueObject is not of type Object (which datagrid.selectedItem is an Object).

             

            So I need a way to first populate an object or a valueObject with the data of datagrid.selectedItem.  That way I don't have to include unnecessary properties like email and phone if they will never change.  And then I can just set the properties I do want to change.

             

            Ideally something like...

            myVO = datagrid.selecteditem;

            myVO.firstName = firstNameInput.text;

            myVO.lastName = lastNameInput.text;

             

            and now email and phone properties are already populated because they took on whatever values were in datagrid.selectedItem.

             

            So, I need some help figuring this out.

             

            >>> Michael Borbor <forums@adobe.com> 4/22/2009 11:36 AM >>>

            Hi there I think that what you need to do is not declare objNew as an object but as the dto or vo that is use to pass data and get data fro CF

            • 3. Re: Using an Object to get datagrid record properties? (update record)
              Michael Borbor Level 4

              Did you try casting your dg selectedItem to your VO?

               

              Sincerely,

               

              Michael

               

              El 22/04/2009, a las 10:46, EvolvedDSM <forums@adobe.com> escribió:

               

              >

              Well, I have tried using the VO and that works fine.  The problem is 

              that not all data properties are available to edit via the form 

              fields, so if I use the VO, I have to specify every property in my 

              function even if they aren't being edited.

              >

              For example, lets set my data contains a firstName, lastName, email, 

              and phone property (or column in the db table).  I do not want the 

              email and phone to be upated, only the firstName and lastName 

              properties.  Yet in my function, for the VO to work, I would have to 

              do this...

              >

              myVO = new valueObject; // valueObject.as contains the data structure

              myVO.firstName = firstNameInput.text;

              myVO.lastName = lastNameInput.text;

              myVO.email = datagrid.selectedItem.email;

              myVO.phone = datagrid.selectedItem.phone;

              >

              The reason I have to do this is because the VO will submit null/

              blank values as default if I do not specify other data to those 

              properties (in this case email and phone).  If I exclude email and 

              phone from myVO above, it will delete any value I might have had 

              previously when the remoteObject method updates with my given data.

              >

              I oringally thought I could do myVO = datagrid.selectedItem, however 

              it will not accept this because my type valueObject is not of type 

              Object (which datagrid.selectedItem is an Object).

              >

              So I need a way to first populate an object or a valueObject with 

              the data of datagrid.selectedItem.  That way I don't have to include 

              unnecessary properties like email and phone if they will never 

              change.  And then I can just set the properties I do want to change.

              >

              Ideally something like...

              myVO = datagrid.selecteditem;

              myVO.firstName = firstNameInput.text;

              myVO.lastName = lastNameInput.text;

              >

              and now email and phone properties are already populated because 

              they took on whatever values were in datagrid.selectedItem.

              >

              So, I need some help figuring this out.

              >

              >>>> Michael Borbor <mailto:forums@adobe.com> 4/22/2009 11:36 AM >>>

              Hi there I think that what you need to do is not declare objNew as 

              an object but as the dto or vo that is use to pass data and get data 

              fro CF

              >

              • 4. Re: Using an Object to get datagrid record properties? (update record)
                EvolvedDSM Level 2

                Yes I have but it fails.  It will only work if I set all the properties

                of the VO to either the form field or to datagrid.selectedItem.property,

                which if I'm doing it this way, I don't even need to set it to the

                selectedItem because I'm manually setting my data now.  This is what I'm

                trying to avoid.  I shouldn't have to type out every property.

                 

                I tried

                myVO = datagrid.selectedItem as valueObject;

                This seems to hold a value, but the update fails unless I give each

                property of the VO a value.  ie, having to set phone and email =

                datagrid.selectedItem.phone/email. 

                 

                Could it be that the data type changes?  For instance, one of the

                columns/properties of the data set is of date data type in my VO, but

                the data type from the datagrid might be changing the date to a string?

                 

                I have a feeling that the tie-up is probably due to the date data type.

                Ugh, I hate dealing with dates.

                 

                 

                 

                >>> Michael Borbor <forums@adobe.com> 4/22/2009 12:10 PM >>>

                Did you try casting your dg selectedItem to your VO?

                 

                Sincerely,

                 

                Michael

                 

                El 22/04/2009, a las 10:46, EvolvedDSM <mailto:forums@adobe.com>

                escribió:

                 

                >

                Well, I have tried using the VO and that works fine.  The problem is

                 

                that not all data properties are available to edit via the form 

                fields, so if I use the VO, I have to specify every property in my 

                function even if they aren't being edited.

                >

                For example, lets set my data contains a firstName, lastName, email,

                 

                and phone property (or column in the db table).  I do not want the 

                email and phone to be upated, only the firstName and lastName 

                properties.  Yet in my function, for the VO to work, I would have to

                 

                do this...

                >

                myVO = new valueObject; // valueObject.as contains the data

                structure

                myVO.firstName = firstNameInput.text;

                myVO.lastName = lastNameInput.text;

                myVO.email = datagrid.selectedItem.email;

                myVO.phone = datagrid.selectedItem.phone;

                >

                The reason I have to do this is because the VO will submit null/

                blank values as default if I do not specify other data to those 

                properties (in this case email and phone).  If I exclude email and 

                phone from myVO above, it will delete any value I might have had 

                previously when the remoteObject method updates with my given data.

                >

                I oringally thought I could do myVO = datagrid.selectedItem, however

                 

                it will not accept this because my type valueObject is not of type 

                Object (which datagrid.selectedItem is an Object).

                >

                So I need a way to first populate an object or a valueObject with 

                the data of datagrid.selectedItem.  That way I don't have to include

                 

                unnecessary properties like email and phone if they will never 

                change.  And then I can just set the properties I do want to change.

                >

                Ideally something like...

                myVO = datagrid.selecteditem;

                myVO.firstName = firstNameInput.text;

                myVO.lastName = lastNameInput.text;

                >

                and now email and phone properties are already populated because 

                they took on whatever values were in datagrid.selectedItem.

                >

                So, I need some help figuring this out.

                >

                >>>> Michael Borbor <mailto:mailto:forums@adobe.com> 4/22/2009 11:36 AM

                >>>

                Hi there I think that what you need to do is not declare objNew as 

                an object but as the dto or vo that is use to pass data and get data

                 

                fro CF

                 

                • 5. Re: Using an Object to get datagrid record properties? (update record)
                  Michael Borbor Level 4

                  Maybe I'll try to reproduce this later and tell you my findings. Did 

                  you try in this way myobj:myVo=new myVo(dg.selectedItem)

                   

                  Sincerely,

                   

                  Michael

                   

                  El 22/04/2009, a las 11:41, EvolvedDSM <forums@adobe.com> escribió:

                   

                  >

                  Yes I have but it fails.  It will only work if I set all the 

                  properties

                  of the VO to either the form field or to 

                  datagrid.selectedItem.property,

                  which if I'm doing it this way, I don't even need to set it to the

                  selectedItem because I'm manually setting my data now.  This is what 

                  I'm

                  trying to avoid.  I shouldn't have to type out every property.

                  >

                  I tried

                  myVO = datagrid.selectedItem as valueObject;

                  This seems to hold a value, but the update fails unless I give each

                  property of the VO a value.  ie, having to set phone and email =

                  datagrid.selectedItem.phone/email.

                  >

                  Could it be that the data type changes?  For instance, one of the

                  columns/properties of the data set is of date data type in my VO, but

                  the data type from the datagrid might be changing the date to a 

                  string?

                  >

                  I have a feeling that the tie-up is probably due to the date data 

                  type.

                  Ugh, I hate dealing with dates.

                  >

                  >

                  >

                  >>>> Michael Borbor <mailto:forums@adobe.com> 4/22/2009 12:10 PM >>>

                  Did you try casting your dg selectedItem to your VO?

                  >

                  Sincerely,

                  >

                  Michael

                  >

                  El 22/04/2009, a las 10:46, EvolvedDSM 

                  <mailto:mailto:forums@adobe.com>

                  escribió:

                  >

                  >>

                  >> Well, I have tried using the VO and that works fine.  The problem is

                  >

                  >> that not all data properties are available to edit via the form

                  >> fields, so if I use the VO, I have to specify every property in my

                  >> function even if they aren't being edited.

                  >>

                  >> For example, lets set my data contains a firstName, lastName, email,

                  >

                  >> and phone property (or column in the db table).  I do not want the

                  >> email and phone to be upated, only the firstName and lastName

                  >> properties.  Yet in my function, for the VO to work, I would have to

                  >

                  >> do this...

                  >>

                  >> myVO = new valueObject; // valueObject.as contains the data

                  structure

                  >> myVO.firstName = firstNameInput.text;

                  >> myVO.lastName = lastNameInput.text;

                  >> myVO.email = datagrid.selectedItem.email;

                  >> myVO.phone = datagrid.selectedItem.phone;

                  >>

                  >> The reason I have to do this is because the VO will submit null/

                  >> blank values as default if I do not specify other data to those

                  >> properties (in this case email and phone).  If I exclude email and

                  >> phone from myVO above, it will delete any value I might have had

                  >> previously when the remoteObject method updates with my given data.

                  >>

                  >> I oringally thought I could do myVO = datagrid.selectedItem, however

                  >

                  >> it will not accept this because my type valueObject is not of type

                  >> Object (which datagrid.selectedItem is an Object).

                  >>

                  >> So I need a way to first populate an object or a valueObject with

                  >> the data of datagrid.selectedItem.  That way I don't have to include

                  >

                  >> unnecessary properties like email and phone if they will never

                  >> change.  And then I can just set the properties I do want to change.

                  >>

                  >> Ideally something like...

                  >> myVO = datagrid.selecteditem;

                  >> myVO.firstName = firstNameInput.text;

                  >> myVO.lastName = lastNameInput.text;

                  >>

                  >> and now email and phone properties are already populated because

                  >> they took on whatever values were in datagrid.selectedItem.

                  >>

                  >> So, I need some help figuring this out.

                  >>

                  >>>>> Michael Borbor <mailto:mailto:mailto:forums@adobe.com> 4/22/2009 

                  >>>>> 11:36 AM

                  >>>>

                  >> Hi there I think that what you need to do is not declare objNew as

                  >> an object but as the dto or vo that is use to pass data and get data

                  >

                  >> fro CF

                  >

                  >

                  • 6. Re: Using an Object to get datagrid record properties? (update record)
                    EvolvedDSM Level 2

                    Ya I had tried that and it returned a problem within Flex Builder saying that it expected a value of no more than 0.

                     

                    I'm going to cfmail a cfdump of my object when it gets sent to the CFC.

                     

                    Also, if it helps, these are the CFC's that are generated with the CF wizard in flex builder.  So if you want a reference and you have ColdFusion with a datasource, check out the update() function.  Previously I had used this same way of udpating data in my last app, but I was also setting every property of the VO manually... so I never ran into this issue.

                     

                    I'll see what the dump says

                     

                     

                    This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain private, confidential, and/or privileged information. Any unauthorized review, use, disclosure, or distribution is prohibited. If you are not the intended recipient, employee, or agent responsible for delivering this message, please contact the sender by reply e-mail and destroy all copies of the original e-mail message.

                    • 7. Re: Using an Object to get datagrid record properties? (update record)
                      EvolvedDSM Level 2

                      I thought emailing my responses would be a convenient way to do things, but then I remembered, "ITS EMAIL" and everything previously in the email gets posted here.

                       

                      Perhaps if we continue using email, we clean up old messages so we don't get lengthy posts.

                       

                      Would be nice if Adobe would handle parsing out >>>>  so old messages do not get posted.

                      • 8. Re: Using an Object to get datagrid record properties? (update record)
                        EvolvedDSM Level 2

                        Issue is with filterFunction and date value.

                         

                        See this thread for a continuation to my issue.

                         

                        http://forums.adobe.com/thread/423386

                        • 9. Re: Using an Object to get datagrid record properties? (update record)
                          Michael Borbor Level 4

                          Hi there, I was playing with the RO and casting stuff and this casting works for me:

                           

                          myData=myVO(myDG.selectedItem)
                          

                          Where myData is a var of type myVO, and myVO is a value object, so I can modify any properties as long as I don't play with the date field I can update the registry without a problem.