11 Replies Latest reply on Aug 4, 2011 11:19 PM by FahaAK

    Unable to map nested java classes and objects in actionscript using flex

    FahaAK Level 1

      Hi All..,

       

      Im a newbie in flex and actionscripting...,I however have a task assigned in this domain and goin insane since a week now with this problem...

      Problem explained:


      I have a class called Unit that inturn have many other classes like for example unit has an engineer class,,,Im not able to access the attributes of engineer using the unit class...that is unit.engineer,engineerid is giving me a null...however attributes unique to unit are accessible...

       

      Please help me out with this...,this problem has already eaten up my deadlines...

      Any help would be appreciated and thankz in advance..

        • 1. Re: Unable to map nested java classes and objects in actionscript using flex
          G1Z Level 1

          have you defined these engineer class as an instance variable ???? Please try to post your code so that we can help you out

          • 2. Re: Unable to map nested java classes and objects in actionscript using flex
            FahaAK Level 1

            Thank you for the swift reply...,

            I actually have three java classes Unit , Engineer and UnitretrievalRemote....

            Unit contains engineer and also UnitRetrievalRemote has methods to retrieve unit which inturn should return engineer...,However i hav actionscript classes for both engineer and unit and mapped it apporopriately using the remotetag...and also my remote object is defined with a destination...

             

            The below code is my Actionscripting code included in mxml:

             

             

            import UnitScript.Engineer;//These are my Action Scripting Classes

            import UnitScript.Unit;

            import mx.collections.ArrayCollection;

            import mx.collections.ArrayList;

            import mx.controls.Alert;

            import mx.events.FlexEvent;

            import mx.rpc.events.ResultEvent;

             

            public var unitIds:ArrayCollection;//I'm passing an array from java end

            that retrieves the unitId's from the db using hibernate...

            public var index:int;

            public var unit:Unit;

            protected function initData():void

            {

            ApplicationService.getUnitIds();

            //This is the remoteobject call using blazeds to load the method during application start from java..

            }

             

            private function setUnitIds(event:ResultEvent):void

            {

            unitIds  = ArrayCollection(event.result);

            }

             

            private function setUnit(event:ResultEvent):void

            {

            unit = Unit(event.result);

            //mx.controls.Alert.show( "Compling" );

            //mx.controls.Alert.show( "Engineer Method" +unit.engineerId);

            //mx.controls.Alert.show( " Engineer=="+unit.engineer) ;

            unitIDText.text = String( unit.unitId );

            customerName.text = unit.name;//displaying the contents fetched from the backend in the panel...

            setEngineer(event);

            }

            private function setEngineer(event:ResultEvent):void

            {

             

            unit.engineer = Engineer(event.result);

            unit = Unit(event.result);

            eng_id.text = String(unit.engineer.engineerId);

            mx.controls.Alert.show( "Engineer ID Please Show"+unit.engineer);

            //This prints a null.

            mx.controls.Alert.show( "Direct Engineer Id" +unit.engineer.category);

            // This prints a null.

            }

             

            Remote object mapping is as below:

            <mx:RemoteObject
                id="ApplicationService"
                destination="Destination1" >
                <mx:method name="getUnitIds" result="setUnitIds(event)"
                fault="mx.controls.Alert.show(event.fault.faultString)"/>
                <mx:method name="getUnit" result="setUnit(event)"
                fault="mx.controls.Alert.show(event.fault.faultString)"/>

            </RemoteObject>

            • 3. Re: Unable to map nested java classes and objects in actionscript using flex
              G1Z Level 1

              R U CALLING getUnit() method of your unit service...I guess this is not there in the code.

              • 4. Re: Unable to map nested java classes and objects in actionscript using flex
                FahaAK Level 1

                getUnit and the getunitIds methods are in the java end.....

                 

                 

                 

                public class ApplicationService
                {
                    private UnitEquipmentMapDAO  unitEquipmentMapDAO;
                    private TaskOrderDAO taskOrderDAO;
                    private EngineerDAO engineerDAO;
                    private UnitDAO unitDAO;
                    private PersonDAO personDAO;
                    private EquipmentDAO equipmentDAO;
                    private ClientDAO clientDAO;
                    private TruckDAO truckDAO;
                    private UnitAssignmentDAO unitAssignmentDAO;
                    private OperatorDAO operatorDAO;
                   
                    public Integer[] getUnitIds()
                    {
                        List units = unitDAO.findAll(); //finds and returns all the units from the database...
                       
                        Integer[] result = new Integer[ units.size() ];
                        for( int i=0 ; i< units.size(); i++ )
                        { 
                            Unit unit =(Unit)units.get( i );
                            result[ i ] = unit.getUnitId();
                           
                        }
                         return result;
                    }
                   
                    public Unit getUnit( Integer id )
                    {
                         Unit unit = unitDAO.findById( id );
                         return unit;
                    }

                 

                 

                This is the Unitretrievalremote class:

                 

                 

                  public ArrayList getUnitIds()
                    {
                       
                        
                        Integer[] ids = appService.getUnitIds();
                        ArrayList result = new ArrayList();
                         for( int i=0; i< ids.length; i++ )
                        {
                             result.add(ids[i]);
                        }
                        System.out.println( "Number of units= " + result.size() );
                        return result;
                        
                    }

                public Unit getUnit( Integer id )
                    {
                        Unit unit = appService.getUnit( id );
                            return unit;
                     }

                 

                 

                The getunitIds call the setunitids() from the actionscript class and also the getunitid calls the setunitid() from the actionscript class thru remote object....

                • 5. Re: Unable to map nested java classes and objects in actionscript using flex
                  G1Z Level 1

                  see you cannot get the data required from two methods of backend in a single shot and from single event. Please fire different event types and your single custom event mate. for example

                   

                   

                  Create a custom event like

                   

                  import mx.events.event;

                   

                   

                  public class CustomEvent extends Event

                  {

                   

                  public static var GET_ID:string="id";

                  public static var GET_UNIT_ID:string="unitid";

                   

                       public function CustomEvent(type:String, data:ArrayCollection=null, bubbles:Boolean=false, cancelable:Boolean=false):void

                       {

                            super(type, data, bubbles, cancelable);

                       }

                  }

                   

                  and your Flex should be able to catch these two types of event types based on the calls to diffrent methods of your service and should get the required data to typecast it into ArrayCollection mate.

                   

                  Hope this helps,

                   

                  Cheers

                  G1

                  1 person found this helpful
                  • 6. Re: Unable to map nested java classes and objects in actionscript using flex
                    FahaAK Level 1

                    Thanks a ton...will try this out....

                    • 7. Re: Unable to map nested java classes and objects in actionscript using flex
                      FahaAK Level 1

                      Hi All...,

                       

                      I'm trying to do some datagrid activity using flex this time.....,

                      I have a java class that gets the data from the database I'm however using hibernate and spring....

                      The problem arises when im trying to get the data displayed in the datagrid component of the flex application using remote method invocation...

                      i have an AS class as well that maps my corresponding java class...however im unable to get my data displayed in the datagrid and also im having the list from java mapped into an arraycollection in AS....but when im trying to print the arraycollection variable length it gives me a null.....the dataprovider property when assigned with the arraycollection variable is not rsponding as i dont see any output getting reflected in the grid...please help me out with this issue....thanks in advance....

                      • 8. Re: Unable to map nested java classes and objects in actionscript using flex
                        FahaAK Level 1

                        If there is anyone who could help me out with this...it would be most appreciated

                        • 9. Re: Unable to map nested java classes and objects in actionscript using flex
                          FahaAK Level 1

                          How do i atleast know that my arraylist from java is mapped to my arraycollection var in AS...,

                          is there a way i can get to see the individual elements of the list in AS...Please help

                          • 10. Re: Unable to map nested java classes and objects in actionscript using flex
                            FahaAK Level 1

                            Hi All...,

                             

                            I have a little misunderstanding about inline itemrenderers, as i mentioned earlier im new to flex please pardon me if this is a silly question..

                            Question:

                            I have an Advanceddatagrid, i have added a column of checkboxes usint inline itemrendered:

                            <itemrenderer = mx.controls.CheckBox">

                            i have the column defined as select i.e....

                            <AdvancedDatagridColumn id="select" itemrenderer="mx.controls.CheckBox">

                            i have a series of columns following this above column...i want to be able to select a particular row

                            upon the selection of the checkbox....i however doubt that im selecting the column("select") and not an individual

                            checkbox....

                            Or in better words "Is there a way where i can reference to these checkboxes individually" as im intending to do

                            some data inserting,deleting and updating activity depending upon the selected checkbox...

                            However i also intend to open another MXML file that contains only that data that is checked by the checkbox...

                            I request you experts to help me out with this....

                            Im trying to do this from 2 days now...., please  help me out....

                            Thanks all in advance..

                            • 11. Re: Unable to map nested java classes and objects in actionscript using flex
                              FahaAK Level 1

                              Hi G1..,

                               

                              I tried out what you had suggested....,but iam afraid the problem still persisted until i  had to just make the lazy loading attribute of the hbm file

                              for that particular DAO set to true..

                              It's perfectly working now....thanks again for all the help...