2 Replies Latest reply on Feb 10, 2010 9:21 AM by iamiqbal

    Flex and Java Web service

    iamiqbal

      Hello:

       

      I am trying to integrate java web service with Flex UI.

      The output from webservice is collection of java objects. I want that to be displayed in grid.

       

      I am not able to display the output obtained from my webs service call into grid. I can display if the output is just a simple string but not collection

      of data objects.

      Appreciate if anyone can help me on this.

       

      I have developed following artifacts.

       

      My java webservice is as below:

       

      /*
      * To change this template, choose Tools | Templates
      * and open the template in the editor.
      */

      package com.mst.soa;

      import java.util.ArrayList;
      import java.util.List;
      import javax.jws.WebMethod;
      import javax.jws.WebService;

      /**
      *
      * @author iamiqbal
      */
      @WebService()
      public class LoggerWS {

          @WebMethod
          public String getLogger(String interfaceName,String fromDate){
              System.out.println("Web service Logger WS invoked");
              return "Batch Started and Completed Successfully";
          }

           public List<Employee> getList(String interfaceName,String fromDate){
              System.out.println("Web service getList method invoked");
              List tempList = new ArrayList();
              Employee emp = new Employee();
              emp.setName("name1");
              tempList.add(emp);
              Employee emp1 = new Employee();
              emp1.setName("name2");
              tempList.add(emp1);
              //tempList.add("name2");
              return tempList;

          }
      }

      My felx application is as below:

       

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

      <mx:Application

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml"

      layout="

      vertical"

      verticalAlign="

      middle"

      backgroundColor="

      white" viewSourceURL="srcview/index.html">

       

       

       

      <mx:Script>

      <![CDATA[

       

       

      import mx.collections.ArrayCollection;

       

      import mx.controls.Alert;

       

      import mx.rpc.events.ResultEvent;

       

      import mx.rpc.events.FaultEvent;

       

      import mx.utils.ObjectUtil;

       

       

      private var startTime:int;

       

      private var endTime:int;

       

      [

      Bindable]

       

      private var dataVar:ArrayCollection;

       

       

      private function button_click():void {

      webServiceGetList.getList.send();

       

      //webService.getLogger.send();

      startTime = getTimer();

      lbl.text =

       

      "Wait.......";

      }

       

       

      private function display(evt:ResultEvent):void {

      textField.text = ObjectUtil.toString(evt.result);

       

      //textField.text += ObjectUtil.toString(evt.result.surname);

      calcTime();

      }

       

       

       

      private function displayList(evt:ResultEvent):void {

       

       

      //dataVar = (ArrayCollection)evt.result;

       

       

      //dataVar = evt.result;

       

       

      //dataVar = evt.result;

       

       

      //ArrayCollection arrayCollection = new ArrayCollection();

       

       

      //textField.text = (evt.result);

       

       

      //textField.text += ObjectUtil.toString(evt.result.surname);

      calcTime();

      }

       

       

       

      private function displayfault(evt:FaultEvent):void {

      Alert.show(evt.type);

      calcTime();

      lbl.text =

      "ERROR:::::";

      }

       

       

      private function calcTime():void {

      endTime = getTimer();

      lbl.text =

      "total time: " + (endTime - startTime) + "ms";

      }

      ]]>

       

      </mx:Script>

       

       

       

      <mx:WebService id="webService"

      wsdl="

      http://localhost:8080/MSTDealWebServices/LoggerWSService?wsdl"

      useProxy="

      false">

       

       

       

      <mx:operation name="getLogger"

      resultFormat="

      object"

      result="display(event);"

      fault="displayfault(event);"

      >

       

       

      <mx:request xmlns="" >

       

       

      <arg0>Iqbal</arg0>

       

       

      <arg1>Mohiuddin</arg1>

       

       

      </mx:request>

       

       

      </mx:operation>

       

       

       

      </mx:WebService>

       

       

       

      <mx:WebService id="webServiceGetList"

      wsdl="

      http://localhost:8080/MSTDealWebServices/LoggerWSService?wsdl"

      useProxy="

      false">

       

       

      <mx:operation name="getList"

      resultFormat="

      object"

      result="displayList(event);"

      fault="displayfault(event);"

      >

       

      <mx:request xmlns="" >

       

      <arg0>Iqbal</arg0>

       

      <arg1>Mohiuddin</arg1>

       

      </mx:request>

       

      </mx:operation>

       

       

      </mx:WebService>

       

       

       

       

      <mx:Label text="Web Service output"/>

       

      <mx:TextInput id="textField"

      editable="

      false" />

       

       

      <mx:DataGrid id="data" dataProvider="{dataVar}"/>

       

       

      <mx:Spacer width="100%" />

       

       

      <mx:ApplicationControlBar dock="true">

       

      <mx:Button id="button"

      label="

      call web service"

      click="button_click();"

      />

       

      <mx:Label id="lbl" />

       

      </mx:ApplicationControlBar>

       

      </mx:Application>

       

      package

       

       

      test

      {

      [

      Bindable]

       

      public class Employee

      {

       

      private var name:String;

       

      public function Employee()

      {

      }

       

      }

      }