1 Reply Latest reply on Aug 1, 2013 9:58 AM by pauland

    Restful and .AS files

    Arundil

      Hi Everyone

       

      I'm triying to conect a Restful servise to and HTTP servide that I have already created on the app, I already make it work when I specify a field but I want to know how can I make that field a variable

       

      I already try puting it on {} but it didnt work, please see the code bellow

       

      package services

      {

                import mx.collections.ArrayCollection;

                import mx.rpc.events.ResultEvent;

                import mx.rpc.http.mxml.HTTPService;

       

                import spark.collections.Sort;

                import spark.collections.SortField;

       

                import valueObjects.Loans;

       

       

       

       

                public class LoansService extends HTTPService

                {

                          [Bindable]

                          public var loanse:ArrayCollection;

       

                          private var selectedfilter:Number = 0;

                          private var selectedfilter2:String = null;

                          private var Y:Number = 0;

                          private var rolle:String = null;

       

                          public function LoansService(rootURL:String=null, destination:String=null)

                          {

                                    super(rootURL, destination);

                                    this.url="http://16.116.35.71:8080/ezdemo/rest/loan/all/{User}"; <- how can I make User to be taken as a variable

                                    this.resultFormat="e4x";

                                    addEventListener(ResultEvent.RESULT, handleLoansResult)

                          }

       

                          protected function handleLoansResult(event:ResultEvent):void {

                                    var loansArray:Array = new Array();

                                    var resultData:XMLList = event.result..loans;

       

                                    for each (var l:XML in resultData) {

                                              var loans:Loans = Loans.buildLoan( l );

                                              loansArray.push( loans );

                                    }

       

                                    loanse = new ArrayCollection( loansArray );

                                    loanse.filterFunction = filterForCategory;

                                    loanse.refresh();

                          }

       

                          private function filterForCategory( item:Loans ):Boolean{

                                    var id:int = selectId(item.status)

       

                                    switch(rolle)

                                    {

                                              case "accountManager":

                                              {

                                                        if (selectedfilter != 0){

                                                                  if (id == selectedfilter){

                                                                            if (item.accountManager == selectedfilter2){

                                                                                      return true;

                                                                            }

                                                                            else return false;

                                                                  }

                                                                  else return false;

                                                        }

                                                        else{

                                                                  if (item.accountManager == selectedfilter2){

                                                                            return true

                                                                  }

                                                                  else {return false}

                                                        }

                                                        break;

                                              }

                                              case "isr":

                                              {

                                                        if (selectedfilter != 0){

                                                                  if (id == selectedfilter){

                                                                            if (item.isr == selectedfilter2){

                                                                                      return true;

                                                                            }

                                                                            else return false;

                                                                  }

                                                                  else return false;

                                                        }

                                                        else{

                                                                  if (item.isr == selectedfilter2){

                                                                            return true

                                                                  }

                                                                  else {return false}

                                                        }

                                                        break;

                                              }

                                              case "isa":

                                              {

                                                        if (selectedfilter != 0){

                                                                  if (id == selectedfilter){

                                                                            if (item.isa == selectedfilter2){

                                                                                      return true;

                                                                            }

                                                                            else return false;

                                                                  }

                                                                  else return false;

                                                        }

                                                        else{

                                                                  if (item.isa == selectedfilter2){

                                                                            return true

                                                                  }

                                                                  else {return false}

                                                        }

                                                        break;

                                              }

       

                                              default:

                                              {

                                                        return false;

                                                        break;

                                              }

       

       

                                    }

                          }

       

                          public function receive(u:String, r:String):void{

                                    selectedfilter2 = u;

                                    rolle = r;

                          }

       

                          public function filterCollection(u:String, x:Number, r:String):void{

                                    selectedfilter = x;

                                    selectedfilter2 = u;

                                    rolle = r;

                                    loanse.filterFunction = filterForCategory;

                                    loanse.refresh();

                          }

       

                          public function sortTable(inc:Number):void

                          {

                                    var sort:Sort = new Sort();

                                    var sorted:String;

                                    var numb:Boolean;

                                    switch(inc)

                                    {

                                              case 0:

                                                        sorted = "companyName";

                                                        numb = false;

                                                        break;

                                              case 1:

                                                        sorted = "loan";

                                                        numb = true;

                                                        break;

                                              case 2:

                                                        sorted = "status";

                                                        numb = false;

                                                        break;

                                    }

                                    var sortfield:SortField = new SortField(sorted,false,numb);

                                    sort.fields = [sortfield];

                                    loanse.sort = sort;

                                    loanse.refresh();

                          }

       

                          private function selectId(o:String):int

                          {

                                    var i:int;

                                    switch (o)

                                    {

                                              case "Product":

                                                        i = 1;

                                                        break;

                                              case "Approvals":

                                                        i = 1;

                                                        break;

                                              case "Allocation":

                                                        i = 1;

                                                        break;

                                              case "Drop Ship":

                                                        i = 1;

                                                        break;

                                              case "Shipping":

                                                        i = 1;

                                                        break;

                                              case "Open Placement":

                                                        i = 2;

                                                        break;

                                              case "Force Clousure Risk":

                                                        i = 2;

                                                        break;

                                    }

                                    return i;

                          }

       

       

                }

      }