1 Reply Latest reply on Aug 9, 2010 10:01 PM by Balakrishnan V

    Event driven service calls

    DNelson72

      I am an extremely novice user so please forgive me if this question seems absolutely mundane.  I know I'm missing something fundamental.

       

      Basically what I want to do is call the service getOMContent when a user clicks an item in the data grid that is populated by the service getCode.  A parameter (codeid) is passed to the service in order to retrieve a single row.  I then want to display the returned data in a text box.

       

      I have included my mxml and php code below.

       

       

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

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

         xmlns:s="library://ns.adobe.com/flex/spark"

         xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:complianceservice="services.complianceservice.*"  xmlns:valueObjects="valueObjects.*">

      <fx:Script>

      <![CDATA[

       

      import mx.controls.Alert;

      import mx.events.FlexEvent;

      import mx.events.ListEvent;

       

       

      protected function dataGrid_creationCompleteHandler(event:FlexEvent):void

      {

      getCodeResult.token = complianceService.getCode();

      }

       

       

      protected function dataGrid_itemClickHandler(event:ListEvent):void

      {

      getOMContentResult.token = complianceService.getOMContent(code.codeid)

      }

       

      ]]>

      </fx:Script>

       

      <fx:Declarations>

      <s:CallResponder id="getCodeResult"/>

      <valueObjects:Code id="code"/>

      <complianceservice:ComplianceService id="complianceService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>

      <valueObjects:Omcont id="omcont"/>

      <s:CallResponder id="getOMContentResult"/>

      <!-- Place non-visual elements (e.g., services, value objects) here -->

      </fx:Declarations>

       

      fx:Binding source="dataGrid.selectedItem as Code" destination="code"/>

       

      <mx:DataGrid x="23" y="25" id="dataGrid" creationComplete="dataGrid_creationCompleteHandler(event)" dataProvider="{getCodeResult.lastResult}" height="143" itemClick="dataGrid_itemClickHandler(event)">

      <mx:columns>

      <mx:DataGridColumn headerText="Code ID" dataField="codeid"/>

      <mx:DataGridColumn dataField="title" headerText="Title"/>

      </mx:columns>

      </mx:DataGrid>

      <s:TextArea x="23" y="194" id="txtReturn" text="{omcont.omcontent}"/>

      </s:Application>

       

      public function getCode() {

           $stmt = mysqli_prepare($this->connection,

                "SELECT

                    code.codeid,

                    code.subpart,

                    code.title,

                    code.codecontent,

                    code.material,

                  code.component,

                    code.type,

                    code.offshore,

                    code.timeinterval,

                    code.procdr,

                    code.tablefigure

                 FROM code

                 ORDER BY code.codeid");    

              

            $this->throwExceptionOnError();

       

            mysqli_stmt_execute($stmt);

            $this->throwExceptionOnError();

       

            $rows = array();

            mysqli_stmt_bind_result($stmt, $row->codeid, $row->subpart, $row->title, $row->codecontent,

      $row->material, $row->component, $row->type, $row->offshore,

      $row->timeinterval, $row->procdr, $row->tablefigure);

       

            while (mysqli_stmt_fetch($stmt)) {

                $rows[] = $row;

                $row = new stdClass();

                mysqli_stmt_bind_result($stmt, $row->codeid, $row->subpart, $row->title, $row->codecontent,

      $row->material, $row->component, $row->type, $row->offshore,

      $row->timeinterval, $row->procdr, $row->tablefigure);

            }

       

            mysqli_stmt_free_result($stmt);

            mysqli_close($this->connection);

       

            return $rows;

        } 

       

       

      public function getOMContent($codeID) {

           $stmt = mysqli_prepare($this->connection,

                "SELECT

                      code.codeid,

                      code.omcontent

                  FROM code

                  WHERE code.codeid LIKE ?");    

              

            $this->throwExceptionOnError();

       

            mysqli_stmt_bind_param($stmt, 's', $codeID);

            $this->throwExceptionOnError();

       

            mysqli_stmt_execute($stmt);

            $this->throwExceptionOnError();

       

            $rows = array();

            mysqli_stmt_bind_result($stmt, $row->codeid, $row->omcontent);

       

            while (mysqli_stmt_fetch($stmt)) {

                $rows[] = $row;

                $row = new stdClass();

                mysqli_stmt_bind_result($stmt, $row->codeid, $row->omcontent);

            }

       

      return $rows;

       

            mysqli_stmt_free_result($stmt);

            mysqli_close($this->connection);

        }

       

        • 1. Re: Event driven service calls
          Balakrishnan V Level 3

          protected function dataGrid_itemClickHandler(event:ListEvent):void

          {

          getOMContentResult.token = complianceService.getOMContent(code.codeid)

          }

           

          I am not sure your Flex code has a definition for code.codeid anywhere.

           

          If its is your intention to choose the id of the clicked row, you could probably try

           

          yourDataGridDataProvider.getItemAt(event.rowIndex).codeid

           

          Hope this helps,

           

          Balakrishnan V