10 Replies Latest reply on Jan 26, 2010 11:45 PM by Scott R. Hamilton

    Data from mySQL query returned but  not being loaded into dataGrid

    Scott R. Hamilton

      Script but the datagrid is not showing any data. (I can
      click in the first four rows of the datagrid but there is
      no data visble.

       

      The debugger is showing the data being returned in the
      Variables section. The 0th row is opened up and it can
      be seen below that the fields title, subtitle and origin
      are being returned from the mySQL rtabel correctly:

       

      record    mx.collections.ArrayCollection (@145f7901)   
          [inherited]   
          [0]    mx.utils.ObjectProxy (@141961f1)   
              object    Object (@14a8c1c9)   
                  origin    "Italien"   
                  subtitle    "Italienische Fischsuppe"   
                  title    "Zuppe die Pesce Venetian"   
                  origin    "Italien"   
                  subtitle    "Italienische Fischsuppe"   
                  title    "Zuppe die Pesce Venetian"   
                  type    null   
                  uid    "94757A3C-C9EF-3F1B-5008-616FA1FDBFC5"   
          [1]    mx.utils.ObjectProxy (@14196311)   
          [2]    mx.utils.ObjectProxy (@141964c1)   
          [3]    mx.utils.ObjectProxy (@141965e1)   
          source    Array (@14ab7511)  

       

      But when I assign the data to the grid with

       

         dgQryRes1.dataProvider = event.result.results.record;
        
      nothing is loaded and also  no error is generated.

       

      Here's the datagrid definition:

       

      <mx:DataGrid id="dgQryRes1" width="795"
         alternatingItemColors="[#F3FBF6, #FFFFFF]"
         borderColor="#AAC1B3" themeColor="#699D55" borderStyle="inset"
         height="267" y="416" x="10" enabled="true" editable="false">
          <mx:columns>
              <mx:DataGridColumn headerText="Title" dataField="sTitle" width="175"/>
              <mx:DataGridColumn headerText="Subtitle" dataField="sSubTitle" width="175"/>
              <mx:DataGridColumn headerText="Origin" dataField="sOrigin" width="100"/>
          </mx:columns>
      </mx:DataGrid>

       

      Can anyone explain to me what the problem is?

        • 1. Re: Data from mySQL query returned but  not being loaded into dataGrid
          Stefan Horochovec Level 2

          Hello

           

          You have a problem with the Serialization of this ArrayCollection. In Flex, you need to declare a [RemoteClass] on object that you have any serialization.

           

          So, from Adobe Docs, see what say to us.

           

          "RemoteClass metadata tag

          Use the [RemoteClass] metadata tag to register the class with Flex so that Flex preserves type information when a class instance is serialized by using Action Message Format (AMF). You insert the [RemoteClass] metadata tag before an ActionScript class definition. The [RemoteClass] metadata tag has the following syntax:

           

          [RemoteClass]

           

          You can also use this tag to represent a server-side Java object in a client application. You use the [RemoteClass(alias=" ")] metadata tag to create an ActionScript object that maps directly to the Java object. You specify the fully qualified class name of the Java class as the value of alias. For more information, see Accessing Server-Side Data with Flex."

           

          So, a example:

           

          package org.flexduck.model

          {

               [Bindable]

               [RemoteClass(alias="org.flexduck.model.Car")]

               public class Car

               {

           

           

                    public var description : String;

           

                   

                    public function Car()

                    {

                         //

                    }

           

               }

          }

           

          If you declared this Metatag, one of atributes have a diferent type on serialization, and, the conversion dont work.

           

          Regards

          • 2. Re: Data from mySQL query returned but  not being loaded into dataGrid
            archemedia Level 4

            Have you tried matching object property names?

             

            record    mx.collections.ArrayCollection (@145f7901)   
                [inherited]   
                [0]    mx.utils.ObjectProxy (@141961f1)   
                    object    Object (@14a8c1c9)   
                        origin    "Italien"   
                        subtitle    "Italienische Fischsuppe"   
                        title    "Zuppe die Pesce Venetian"   
                        origin    "Italien"   
                        subtitle    "Italienische Fischsuppe"   
                        title    "Zuppe die Pesce Venetian"   
                        type    null   
                        uid    "94757A3C-C9EF-3F1B-5008-616FA1FDBFC5"   
                [1]    mx.utils.ObjectProxy (@14196311)   
                [2]    mx.utils.ObjectProxy (@141964c1)   
                [3]    mx.utils.ObjectProxy (@141965e1)   
                source    Array (@14ab7511) 

             

            But when I assign the data to the grid with

             

               dgQryRes1.dataProvider = event.result.results.record;
              
            nothing is loaded and also  no error is generated.

             

            Here's the datagrid definition:

             

            <mx:DataGrid id="dgQryRes1" width="795"
               alternatingItemColors="[#F3FBF6, #FFFFFF]"
               borderColor="#AAC1B3" themeColor="#699D55" borderStyle="inset"
               height="267" y="416" x="10" enabled="true" editable="false">
                <mx:columns>
                    <mx:DataGridColumn headerText="Title" dataField="sTitle" width="175"/>
                    <mx:DataGridColumn headerText="Subtitle" dataField="sSubTitle" width="175"/>
                    <mx:DataGridColumn headerText="Origin" dataField="sOrigin" width="100"/>
                </mx:columns>
            </mx:DataGrid>

            • 3. Re: Data from mySQL query returned but  not being loaded into dataGrid
              Scott R. Hamilton Level 1

              Thanks for your replies.

               

              Stefan,

               

              you've completely lost me with your answer. I have no idea how I could

              implement your wrokaround.

               

              Archimedia,

               

              I tried giveing the data columns an id attribute and then assigning the

              column to the data from the query but the complier would not re-

              cognize the column. Or how would you accomplish your suggestion?

               

              According to the documentation the datagrid should have a default

              dataprovider which can be referenced as dgQryRes1.dataprovider

              which is exactly what I have done. No error is produced, the data

              is returned to my program but the control doesn't show any data.

               

              Strangely enough, the first four rows of the datagrid can be selected

              with the mouse and they change color to signal that they are

              active. Four rows were returned from the database so it looks like

              the data grid is maybe getting the rows and hiding the field values

              somewhere . BTW the other rows in the datagrid (5 - 8) cannot be

              selected. This leads me to believe that the data has somehow made

              it to the datagrid but is being masked out.

               

              Scott

              • 4. Re: Data from mySQL query returned but  not being loaded into dataGrid
                Stefan Horochovec Level 2

                Ok, i show a complete example for this implementation, i considered a project with Java backend, but work at same on PHP, .NET or other tecnology.

                 

                In Flex. The User.as model

                 

                package org.flexduck.model

                {

                 

                     [Bindable]

                     [RemoteClass(alias="org.flexduck.model.User")]

                     public class User

                     {

                 

                          public var cod : Number;

                 

                          public var name : String;

                 

                 

                 

                          public function User()

                          {

                               //

                          }

                     }

                }

                 

                In Java, The User.java model

                 

                package org.flexduck.model;

                 

                import javax.persistence.Column;

                import javax.persistence.Entity;

                import javax.persistence.GeneratedValue;

                import javax.persistence.Transient;

                 

                import static javax.persistence.GenerationType.IDENTITY;

                import javax.persistence.Id;

                import javax.persistence.Table;

                 

                /**

                * User entity.

                */

                @Entity

                @Table(name = "user")

                public class User implements java.io.Serializable {

                 

                     private static final long serialVersionUID = 1L;

                 

                     @Id

                     @GeneratedValue(strategy = IDENTITY)

                     @Column(name="cod", unique = true, nullable = false)

                     private Integer cod;

                 

                 

                     @Column(name="name")

                     private String name;

                 

                     public Integer getCod() {

                          return cod;

                     }

                 

                     public void setCod(Integer cod) {

                          this.cod = cod;

                     }

                 

                     public Integer getName() {

                          return name;

                     }

                 

                     public void setName(String name) {

                          this.name = name;

                     }

                 

                }

                 

                Well. at this point, i have two models, one in backend (Java), and one in my frontend (Flex).

                 

                So, in my UserService.java on my backend to result the list to Flex:

                 

                package org.flexduck.service;

                 

                import java.util.ArrayList;

                import org.hibernate.transform.Transformers;

                import org.flexduck.model.User;

                import org.flexduck.persistence.GenericDAO;

                 

                public class UserService {

                 

                 

                     public UserService() {

                 

                     }

                 

                 

                     public ArrayList<User> findAll() {

                 

                          GenericDAO dao = new GenericDAO();

                          ArrayList<User> list = (ArrayList<User>) dao.findAll(new User());

                          return list;

                 

                     }

                 

                 

                }

                 

                At this point i have a service to obtains the list of Users...

                 

                And finally, in Flex, to list this remote service:

                 

                UserList.mxml

                 

                <?xml version="1.0" encoding="utf-8"?>

                <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" creationComplete="findUsers();">

                 

                <mx:Script>

                     <![CDATA[

                          import mx.collections.ArrayCollection;

                          import mx.rpc.events.ResultEvent;

                          import mx.rpc.events.FaultEvent;

                 

                 

                          [Bindable]

                          private var provider : ArrayCollection = new ArrayCollection();

                 

                 

                          private function onFaultHandler(event:FaultEvent) : void

                          {

                               //

                          }

                 

                 

                          private function onFindAllHandler(event:ResultEvent) : void

                          {

                               this.provider = event.result as ArrayCollection;

                          }

                 

                 

                          private function findUsers() : void

                          {

                               this.userService.findAll();

                          }

                 

                 

                     ]]>

                </mx:Script>

                 

                <mx:RemoteObject id="userService" destination="UserService" showBusyCursor="true" fault="onFaultHandler(event)">

                     <mx:method name="findAll" result="onFindAllHandler(event)" fault="onFaultHandler(event)"/>

                </mx:RemoteObject>

                 

                <mx:AdvancedDataGrid

                     id="adg1"

                     dataProvider="{this.provider}"

                     designViewDataType="flat"

                     bottom="30" left="10"right="10" top="0">

                     <mx:columns>

                          <mx:AdvancedDataGridColumn dataField="cod"/>

                          <mx:AdvancedDataGridColumn dataField="name"/>

                     </mx:columns>

                </mx:AdvancedDataGrid>

                 

                 

                </mx:Canvas>

                 

                Well,

                 

                In this UserList.mxml i have a event on creationComplete and this event send a remote object to consult the list of users. On return, i will send to datagrid provider the arraylist of my users.

                 

                In advancedDataGridColumn, the dataField attribute have the same name for attributes of User object, declared in my Flex Model and in my Java model.

                 

                Regards

                 

                 

                • 5. Re: Data from mySQL query returned but  not being loaded into dataGrid
                  Scott R. Hamilton Level 1

                  Well, I've figured out what the problem was.

                  It was the DataGridColumns that I defined in the DataGrid.

                   

                  I removed them and now the datagrid is being loaded.

                   

                  But now I have completely lost control over the column attributes
                  and the way that they are displayed. In fact,  ordering is exactly
                  backwards to that in the SQL SELECT statement.

                   

                  How do I get my data into a datagrid with DataGridColumn definitions?

                   

                  Scott

                  • 6. Re: Data from mySQL query returned but  not being loaded into dataGrid
                    rick@cat

                    Your object keys are all lower case but your column dataField names are upper and lower like this:

                     

                    <mx:DataGridColumn headerText="Origin" dataField="sOrigin" width="100"/>

                     

                    they have to match and are case sensitive. So it should be:

                     

                    <mx:DataGridColumn headerText="Origin" dataField="origin" width="100"/>

                     

                    Rick

                    • 7. Re: Data from mySQL query returned but  not being loaded into dataGrid
                      Scott R. Hamilton Level 1

                      Thanks Rick,

                       

                      that solved the problem.

                       

                      Scott

                      • 8. Re: Data from mySQL query returned but  not being loaded into dataGrid
                        archemedia Level 4

                        Please read our posts more carefully: I pointed this out the day before yesterday already!

                         

                        d

                        • 9. Re: Data from mySQL query returned but  not being loaded into dataGrid
                          Stefan Horochovec Level 2

                          Hello

                           

                          The first error on application is the ResultEvent contains a ArrayCollection with a list of ObjectProxy, and the second is a incorret information on DataGridColumn.

                           

                          Regards