3 Replies Latest reply on Oct 31, 2007 9:11 AM by ntsiii

    Problem with integrating Flex app and jsp


      I am trying a basic program to integrate Flex UI with a JSP. All I
      want to do is send a request to a JSP and display the data in a
      datagrid. Upon clicking the button, the datagrid displays but with no
      data. Could some one tell me what I am missing? Below is the code. I
      copied the SWF file and HTML wrapper to the application root directory.

      I am using Flex Builder 3 and Tomcat.

      thanks in advance,

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"

      <mx:HTTPService id="employees" useProxy="false" method="POST"
      url="" />

      <mx:DataGrid x="92" y="98" id="datagrid"
      dataProvider="{employees.lastResult.people.person}" visible="false">
      <mx:DataGridColumn headerText="Name" dataField="name"/>
      <mx:DataGridColumn headerText="Age" dataField="age"/>
      <mx:DataGridColumn headerText="Skills" dataField="skills"/>

      <mx:Button x="92" y="261" label="Get Data"


      <title>Server CINT Aggregate results</title>
      out.println("<?xml version=\"1.0\"
      HTML, SQL</skills></person></people>");
        • 1. Re: Problem with integrating Flex app and jsp
          ntsiii Level 3
          First hit the jsp from a browser. Do you see good xml. Hmm, *don't* include the <?xml.. declaration.
          Set resultFormat="e4x" on the http service.
          Then, do not bind directly to last result. it is too hard to debug. Instead us a result handler. in that handler trace() your result to make sure it is what you expect.

          Belwo are some snippets of code to follow. You can ignore the AsyncToken for now.

          Sample code using HTTPService, e4x, handler function to populate a list item.
          Also shows usage of AsyncToken.

          The DataGrid tag:
          <mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>

          The HTTPService tag:
          <mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)" fault="..../>

          Script block declaration:
          import mx.rpc.Events.ResultEvent;
          [Bindable]private var _xlcMyListData:XMLListCollection;

          Invoke send:
          var oRequest:Object = new Object();
          oRequest.Arg1 = "value1";
          var callToken:AsyncToken = service.send(oRequest);
          token.callId = "myQuery1";

          Result Handler function:
          private function onResult(oEvent:ResultEvent):void {
          var xmlResult:XML = XML(event.result); //converts result Object to XML. can also use "as" operator
          var xlMyListData:XMLList = xmlResult.myListData; //depends on xml format, is row data
          _xlcMyListData = new XMLListCollection(xlMyListData); //wrap the XMLList in a collection
          trace(_xlcMyListData.toXMLString()); //so you can see exactly how to specify dataField or build labelFunction
          var callToken:AsyncToken = oEvent.token;
          var sCallId = callToken.callId; //"myQuery1"
          switch(sCallId) { //Process the result conditionally
          case "myQuery1":
          doQuery2(); //do whatever
          • 2. Re: Problem with integrating Flex app and jsp
            Nataraj_Paila Level 1
            Thanks Tracy. For now getting rid of the html tags solved the problem. But I do take your point regarding the event handler, tracing and will follow up on that.
            • 3. Re: Problem with integrating Flex app and jsp
              ntsiii Level 3
              Especially, "Set resultFormat="e4x" on the http service."

              You will be very sorry soon if you do not start doing that immediately.