6 Replies Latest reply on May 26, 2010 12:29 PM by alexlizn

    Advanced Data Grid be passed to Java

    alexlizn Level 1

      Hi, guys,

      I'm thinking about passing an Advanced Data Grid as ArrayList to a Java program where the Arraylist is processed.

       

      is it doable? If it is not, when I pass Advanced Data Grid to Java, what type should that be in Java?

       

      Thanks!

      Alex

        • 1. Re: Advanced Data Grid be passed to Java
          Dajji Level 3

          I believe ArrayList in Java is similar to ArrayCollection of Flex. The dataProvider of AdvancedDataGrid can be an ArrayCollection with nested children. You can pass this ArrayCollection to Java as ArrayList. Alternative would be to pass it as xml and parse it in Java.

          1 person found this helpful
          • 2. Re: Advanced Data Grid be passed to Java
            alexlizn Level 1

            Dajji,

            could you tell me how to convert AdvancedDataGrid to ArrayCollection?

             

            Thanks!

            • 3. Re: Advanced Data Grid be passed to Java
              Dajji Level 3

              AdvancedDataGrid is a component which renders and displays hierarchical data. This data is passed to the grid in the form of ArrayCollection. You can use the same object and pass it to Java. I am not sure if your requirement is to display static data or it is a dynamic data with some user inputs. We can discuss this further, If you can brief your requirement.

              1 person found this helpful
              • 4. Re: Advanced Data Grid be passed to Java
                alexlizn Level 1

                Dajji,

                Thanks for your prompt reply.

                 

                In my app, the page allows users to add, update and delete address rows from the Advanced Data Grid.These are how I did it so far:

                 

                • Insert: adg1.dataProvider.addItem(address);
                • Update: make adg1's editable="true"
                • Delete: adg1.dataProvider.removeItemAt(adg1.selectedIndex);
                •  

                  The changes stay in the data grid until in the end when users click the Submit button to submit all of the rows in the data grid to the PostgreSQL DB. This is the click handler of the submit button:

                   

                  protected function Submit_Btn_clickHandler(event:MouseEvent):void
                              {
                                  processAddressesResult.token = addressService.processAddresses(adg1);
                              }
                  

                   

                  You see I  wanna pass all of the address rows in the advanced data grid as ArrayCollection to my Java program processAddresses() which takes
                  ArrayList<Address> as input.

                   

                  But Flash Builder tells me the click handler was wrong. I'll put up the error msg tomorrow. Do you know why?

                  Thanks a lot!

                  Alex

                  • 5. Re: Advanced Data Grid be passed to Java
                    Dajji Level 3

                    Alex,

                     

                    What you are trying to do is pass AdvancedDataGrid component to Java. You need to pass only data within the grid. One of the most powerful features of Flex is binding. you can use that to update your ArrayCollection and pass this to Java. Following is what it will look like.

                     

                    <mx:Application  xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
                         <mx:Script>
                              <![CDATA[
                                   private var myDP:ArrayCollection;
                    
                                   //Initialize ArrayCollection with any previously entered addresses
                                   private function init():void{
                                        myDP = new ArrayCollection();
                                   }
                    
                                   //Add new address to ArrayCollection, since binding is used, DataGrid will update automatically.
                                   private function addClick_Handler():void{
                                        myDp.addItem(address);
                                   }
                    
                                   //Submit ArrayCollection to Java
                                   private function submitClick_Handler():void{
                                        processAddressesResult.token = addressService.processAddresses(myDp);
                                   }
                    
                              ]]>              
                         </mx:Script>
                         <mx:AdvancedDataGrid dataProvider="{myDP}"/>
                         <mx:Button label="Add" click="addClick_Handler()"/>
                         <mx:Button label="Submit" click="submitClick_Handler()"/>
                    
                    </mx:Application>
                    

                     

                    Hope this will help you solve the problem. If it does, mark the post appropriately.

                    • 6. Re: Advanced Data Grid be passed to Java
                      alexlizn Level 1

                      Dajji,

                      Thanks. I just tried. It worked like a charm.

                      appreciate it.