5 Replies Latest reply on Apr 30, 2009 12:44 PM by ATIF FAROOQ

    Serializing database query results for use as dataproviders

    Cr99 Level 1

      I am executing my database queries in Java and passing my results to flex and creating a chart or datagrid based on the results.  The problem is, I don't know how to code this in Java in a way that flex would understand it.  For instance, Flex wants:

       

      <mx:DataGrid id="dg"  dataProvider="{myArray}">

        <mx:columns>

               <mx:DataGridColumn dataField="column1" />

               <mx:DataGridColumn dataField="column2" />

                <!-- etc ... -->

               <mx:DataGridColumn dataField="columnN" />

            </mx:columns>

      </mx:DataGrid>

       

      I need to create this table-like array in Java and have it readable as a dataprovider by flex.  I know about ArrayCollections and Java ArrayLists can be nicely converted to this in Flex, but I just don't know how to create them with a column1, column2, etc. when I don't know from query to query how many columns will be in my results.

       

      Any help would be greatly appreciated!

        • 1. Re: Serializing database query results for use as dataproviders
          Michael Borbor Level 4

          You don't know in advanced the columns that your queries will return? 

          Or the number of records?

           

          Sincerely,

           

          Michael

           

          El 30/04/2009, a las 13:47, Cr99 <forums@adobe.com> escribió:

           

          >

          I am executing my database queries in Java and passing my results to 

          flex and creating a chart or datagrid based on the results.  The 

          problem is, I don't know how to code this in Java in a way that flex 

          would understand it.  For instance, Flex wants:

          >

          <mx:DataGrid id="dg"  dataProvider="">

            <mx:columns>

                   <mx:DataGridColumn dataField="column1" />

                   <mx:DataGridColumn dataField="column2" />

                    <!-- etc ... -->

                   <mx:DataGridColumn dataField="columnN" />

                </mx:columns>

          </mx:DataGrid>

          >

          I need to create this table-like array in Java and have it readable 

          as a dataprovider by flex.  I know about ArrayCollections and Java 

          ArrayLists can be nicely converted to this in Flex, but I just don't 

          know how to create them with a column1, column2, etc. when I don't 

          know from query to query how many columns will be in my results.

          >

          Any help would be greatly appreciated!

          >

          • 2. Re: Serializing database query results for use as dataproviders
            ATIF FAROOQ Level 3

            hi,

               you can simply construct an xml Structure in java  e.g

             

               returned record from the database have such fields

               Name:some Name

               Email:some Email

               Phone Number : Phone Number

             

               you can build Xml Structure from that e.g

               

               <Address>

                    <Name>some Name</Name>

                    <Email>some Email</Email>

                     <Phone Number>Phone Number</Phone>

              </Address>

             

            you can send this xml back in response to flex from java

             

            then your httpService will automatically serialize that  e.g

             

            <mx:HttpService url='your java page url' id='javaService'>

             

            then in your DataGrid

             

            you can simply

             

            <mx:DataGrid dataProvider="{javaService.lastResult.Address}"/>

             

            and if the fields returned from the database are not  consistent then you can ommit DataGridColumn in the datagrid flex will automatically make columsn on the base of the result.

            • 3. Re: Serializing database query results for use as dataproviders
              Cr99 Level 1

              Thanks for the reply.  Xml seems like a good possibility in some cases, but I am actually passing back an object via remoting and then Flex serializes it into Actionscript.  The reason I chose this method was because I need the server to 'push' the data onto flex.  I also have some large datasets to send sometimes, and read that messaging uses AMF format which is faster than XML. 

               

              So I send the java objects in the messages I push out to the flex app and then use the Actionscript equivalents I have serialized to display the data in flex.  Is there a Java equivalent to Flex's XML class?  Or are there other objects I could use in Flex as Dataproviders besides ArrayCollection and Java's ArrayList?

              • 4. Re: Serializing database query results for use as dataproviders
                Michael Borbor Level 4

                In Java you can use Collection, Object, Map. But the best will be to 

                create dto or vo in Java and in AS

                 

                Sincerely,

                 

                Michael

                 

                El 30/04/2009, a las 14:14, Cr99 <forums@adobe.com> escribió:

                 

                >

                Thanks for the reply.  Xml seems like a good possibility in some 

                cases, but I am actually passing back an object via remoting and 

                then Flex serializes it into Actionscript.  The reason I chose this 

                method was because I need the server to 'push' the data onto flex.  

                I also have some large datasets to send sometimes, and read that 

                messaging uses AMF format which is faster than XML.

                >

                So I send the java objects in the messages I push out to the flex 

                app and then use the Actionscript equivalents I have serialized to 

                display the data in flex.  Is there a Java equivalent to Flex's XML 

                class? Or are there other objects I could use in Flex as 

                Dataproviders besides ArrayCollection and Java's ArrayList?

                >