• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

trouble executing "some" auto generated php remote services...?

New Here ,
Jul 17, 2010 Jul 17, 2010

Copy link to clipboard

Copied

Hi,

I was using the flash builder 4 premium trial with the 4.0 sdk, recently I bought the CS5 web premium suite. It includes flash builder 4.0.1 standard with 4.1 sdk.

1. create a new flex project (as in the welcome tutorial)

2. create a sample PHP service using my db infos (let it install Zend_AMF for me)

3. place a datagrid in the desing mode,

4. drop the the "getAll()" method on it

5. tweek some columns,

6. it works, I see the service call and answer with service capture (an external AMF service monitor).

the 2 problems that appear now (which were not existing in the 4.0 trial version I had)

1) add a new item

protected var newItem:dbItem;

protected function addBtn_clickHandler(event:MouseEvent):void

{

newItem = new dbItem();

newItem.attribute = 'someValue';

this.addDbItem(newItem:dbItem);

}

protected function addDbItem(item:dbItem:void

{

createDbItemResult.token = dbItemService.createDbItem(item);

}

<s:Button label="new item" id="addBtn" click="addBtn_clickHandler(event)"/>


When I click the button, absolutely NOTHING happens, no error, no service call, nothing at all.

----------------------

2) refresh the datagrid's dataprovider

I followed the tutorial on how to bind an ArrayCollection to the dataGrid instead of binding it to "service.lastresult"

populate the ArrayCollection with the service result handler with event.result as ArrayCollection... everything works like before. whe the datagrid is created, it calls the "dataGrid_creationCompleteHandler".

protected function dataGrid_creationCompleteHandler(event:FlexEvent):void

{

this.getAllDbItem();

}

protected function refreshBtn_clickHandler(event:MouseEvent):void

{

this.getAllDbItem();

}

protected function getAllDbItemResult_resultHandler(event:ResultEvent):void

{

DbItems = event.result as ArrayCollection;

}

<s:Button label="refresh" id="refreshBtn" click="refreshBtn_clickHandler(event)"/>

this works!, the refresh button also works, BUT... it only refreshes item which have not bee edited within the app... if I change some item value with a form, (still using skills from the tutorial) :
- the data in the datagrid ARE UPDATED.
- the service.update(item) method DOES NOT EXECUTE (like the create above)
- if I update the DB manualy, ONLY the NON UPDATED rows refresh...
Any idea?
Thank you! I'm stuck here for hours and hours now 😞
the full MXML code

<?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:moniteurservice="services.moniteurservice.*" xmlns:valueObjects="valueObjects.*">

<fx:Script>

<![CDATA[

import mx.collections.ArrayCollection;

import mx.controls.Alert;

import mx.events.FlexEvent;

import mx.rpc.events.ResultEvent;

[Bindable]

protected var moniteurs:ArrayCollection = new ArrayCollection();

protected function dataGrid_creationCompleteHandler(event:FlexEvent):void

{

getAllMoniteurResult.token = moniteurService.getAllMoniteur();

}

protected function button_clickHandler(event:MouseEvent):void

{

moniteur.statut = statutTextInput.text;

moniteur.nom = nomTextInput.text;

moniteur.prenom = prenomTextInput.text;

moniteur.tel = telTextInput.text;

moniteur.mobile = mobileTextInput.text;

moniteur.email = emailTextInput.text;

moniteur.adresse = adresseTextInput.text;

moniteur.npa = npaTextInput.text;

moniteur.lieu = lieuTextInput.text;

moniteur.pays = paysTextInput.text;

this.updateMoniteur(moniteur);

}

protected function updateMoniteur(item:Moniteur):void

{

updateMoniteurResult.token = moniteurService.updateMoniteur(item);

}


protected function button1_clickHandler(event:MouseEvent):void

{

getAllMoniteurResult.token = moniteurService.getAllMoniteur();

}



protected function getAllMoniteurResult_resultHandler(event:ResultEvent):void

{

moniteurs = event.result as ArrayCollection;

}


]]>

</fx:Script>

<fx:Declarations>

<s:CallResponder id="getAllMoniteurResult" result="getAllMoniteurResult_resultHandler(event)"/>

<moniteurservice:MoniteurService id="moniteurService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>

<valueObjects:Moniteur id="moniteur"/>

<s:CallResponder id="updateMoniteurResult"/>

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

</fx:Declarations>

<fx:Binding source="dataGrid.selectedItem as Moniteur" destination="moniteur"/>

<mx:DataGrid x="25" y="24" id="dataGrid" creationComplete="dataGrid_creationCompleteHandler(event)"

dataProvider="{moniteurs}">

<mx:columns>

<mx:DataGridColumn headerText="id" dataField="id"/>

<mx:DataGridColumn headerText="statut" dataField="statut"/>

<mx:DataGridColumn headerText="nom" dataField="nom"/>

<mx:DataGridColumn headerText="prenom" dataField="prenom"/>

<mx:DataGridColumn headerText="tel" dataField="tel"/>

<mx:DataGridColumn headerText="mobile" dataField="mobile"/>

<mx:DataGridColumn headerText="email" dataField="email"/>

<mx:DataGridColumn headerText="adresse" dataField="adresse"/>

<mx:DataGridColumn headerText="npa" dataField="npa"/>

<mx:DataGridColumn headerText="lieu" dataField="lieu"/>

<mx:DataGridColumn headerText="pays" dataField="pays"/>

</mx:columns>

</mx:DataGrid>

<mx:Form defaultButton="{button}" x="25" y="174">

<mx:FormItem label="Statut">

<s:TextInput id="statutTextInput" text="{moniteur.statut}"/>

</mx:FormItem>

<mx:FormItem label="Nom">

<s:TextInput id="nomTextInput" text="{moniteur.nom}"/>

</mx:FormItem>

<mx:FormItem label="Prenom">

<s:TextInput id="prenomTextInput" text="{moniteur.prenom}"/>

</mx:FormItem>

<mx:FormItem label="Tel">

<s:TextInput id="telTextInput" text="{moniteur.tel}"/>

</mx:FormItem>

<mx:FormItem label="Mobile">

<s:TextInput id="mobileTextInput" text="{moniteur.mobile}"/>

</mx:FormItem>

<mx:FormItem label="Email">

<s:TextInput id="emailTextInput" text="{moniteur.email}"/>

</mx:FormItem>

<mx:FormItem label="Adresse">

<s:TextInput id="adresseTextInput" text="{moniteur.adresse}"/>

</mx:FormItem>

<mx:FormItem label="Npa">

<s:TextInput id="npaTextInput" text="{moniteur.npa}"/>

</mx:FormItem>

<mx:FormItem label="Lieu">

<s:TextInput id="lieuTextInput" text="{moniteur.lieu}"/>

</mx:FormItem>

<mx:FormItem label="Pays">

<s:TextInput id="paysTextInput" text="{moniteur.pays}"/>

</mx:FormItem>

<s:Button id="button" label="Submit" click="button_clickHandler(event)"/>

</mx:Form>

<s:Button x="322" y="200" label="Button" click="button1_clickHandler(event)"/>

</s:Application>

the full PHP service code:
<?php
/**
*  README for sample service
*
*  This generated sample service contains functions that illustrate typical service operations.
*  Use these functions as a starting point for creating your own service implementation. Modify the
*  function signatures, references to the database, and implementation according to your needs.
*  Delete the functions that you do not use.
*
*  Save your changes and return to Flash Builder. In Flash Builder Data/Services View, refresh
*  the service. Then drag service operations onto user interface components in Design View. For
*  example, drag the getAllItems() operation onto a DataGrid.
*  This code is for prototyping only.
*  Authenticate the user prior to allowing them to call these methods. You can find more
*
*/
class MoniteurService {
var $username = "root";
var $password = "mikedev";
var $server = "localhost";
var $port = "8889";
var $databasename = "test_db";
var $tablename = "moniteur";
var $connection;
/**
* The constructor initializes the connection to database. Everytime a request is
* received by Zend AMF, an instance of the service class is created and then the
* requested method is invoked.
*/
public function __construct() {
   $this->connection = mysqli_connect(
   $this->server, 
   $this->username, 
   $this->password,
   $this->databasename,
   $this->port
   );
$this->throwExceptionOnError($this->connection);
}
/**
* Returns all the rows from the table.
*
* Add authroization or any logical checks for secure access to your data
*
* @Return array
*/
public function getAllMoniteur() {
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->statut, $row->nom, $row->prenom, $row->tel, $row->mobile, $row->email, $row->adresse, $row->npa, $row->lieu, $row->pays);
    while (mysqli_stmt_fetch($stmt)) {
      $rows[] = $row;
      $row = new stdClass();
      mysqli_stmt_bind_result($stmt, $row->id, $row->statut, $row->nom, $row->prenom, $row->tel, $row->mobile, $row->email, $row->adresse, $row->npa, $row->lieu, $row->pays);
    }
mysqli_stmt_free_result($stmt);
    mysqli_close($this->connection);
    return $rows;
}
/**
* Returns the item corresponding to the value specified for the primary key.
*
* Add authorization or any logical checks for secure access to your data
*
*
* @Return stdClass
*/
public function getMoniteurByID($itemID) {
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where id=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_bind_result($stmt, $row->id, $row->statut, $row->nom, $row->prenom, $row->tel, $row->mobile, $row->email, $row->adresse, $row->npa, $row->lieu, $row->pays);
if(mysqli_stmt_fetch($stmt)) {
      return $row;
} else {
      return null;
}
}
/**
* Returns the item corresponding to the value specified for the primary key.
*
* Add authorization or any logical checks for secure access to your data
*
*
* @Return stdClass
*/
public function createMoniteur($item) {
$stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (id, statut, nom, prenom, tel, mobile, email, adresse, npa, lieu, pays) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'issssssssss', $item->id, $item->statut, $item->nom, $item->prenom, $item->tel, $item->mobile, $item->email, $item->adresse, $item->npa, $item->lieu, $item->pays);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = $item->id;
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}
/**
* Updates the passed item in the table.
*
* Add authorization or any logical checks for secure access to your data
*
* @Param stdClass $item
* @Return void
*/
public function updateMoniteur($item) {
$stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET statut=?, nom=?, prenom=?, tel=?, mobile=?, email=?, adresse=?, npa=?, lieu=?, pays=? WHERE id=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'ssssssssssi', $item->statut, $item->nom, $item->prenom, $item->tel, $item->mobile, $item->email, $item->adresse, $item->npa, $item->lieu, $item->pays, $item->id);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
/**
* Deletes the item corresponding to the passed primary key value from
* the table.
*
* Add authorization or any logical checks for secure access to your data
*
*
* @Return void
*/
public function deleteMoniteur($itemID) {
$stmt = mysqli_prepare($this->connection, "DELETE FROM $this->tablename WHERE id = ?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
/**
* Returns the number of rows in the table.
*
* Add authorization or any logical checks for secure access to your data
*
*
*/
public function count() {
$stmt = mysqli_prepare($this->connection, "SELECT COUNT(*) AS COUNT FROM $this->tablename");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_bind_result($stmt, $rec_count);
$this->throwExceptionOnError();
mysqli_stmt_fetch($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rec_count;
}
/**
* Returns $numItems rows starting from the $startIndex row from the
* table.
*
* Add authorization or any logical checks for secure access to your data
*
*
*
* @Return array
*/
public function getMoniteur_paged($startIndex, $numItems) {
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename LIMIT ?, ?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'ii', $startIndex, $numItems);
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->statut, $row->nom, $row->prenom, $row->tel, $row->mobile, $row->email, $row->adresse, $row->npa, $row->lieu, $row->pays);
    while (mysqli_stmt_fetch($stmt)) {
      $rows[] = $row;
      $row = new stdClass();
      mysqli_stmt_bind_result($stmt, $row->id, $row->statut, $row->nom, $row->prenom, $row->tel, $row->mobile, $row->email, $row->adresse, $row->npa, $row->lieu, $row->pays);
    }
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
/**
* Utility function to throw an exception if an error occurs
* while running a mysql command.
*/
private function throwExceptionOnError($link = null) {
if($link == null) {
$link = $this->connection;
}
if(mysqli_error($link)) {
$msg = mysqli_errno($link) . ": " . mysqli_error($link);
throw new Exception('MySQL Error - '. $msg);
}
}
}
?>

Views

671

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jul 18, 2010 Jul 18, 2010

>

>  the service.update(item) method DOES NOT EXECUTE (like the create above)

>

I think you are not using the "commit" on the service. By default the Data services are "managed".

Data management features allow you to synchronize adding, updating, and deleting of records in a database. Changes you make in the client application are not written to the server until a "commit" method is called. You can call a revert method to roll back changes made in the client application.

So wherever you update or cr

...

Votes

Translate

Translate
Explorer ,
Jul 18, 2010 Jul 18, 2010

Copy link to clipboard

Copied

>

>  the service.update(item) method DOES NOT EXECUTE (like the create above)

>

I think you are not using the "commit" on the service. By default the Data services are "managed".

Data management features allow you to synchronize adding, updating, and deleting of records in a database. Changes you make in the client application are not written to the server until a "commit" method is called. You can call a revert method to roll back changes made in the client application.

So wherever you update or create add "commit" to the service after adding/updating. for eg.

protected function addDbItem(item:dbItem:void

{

     createDbItemResult.token = dbItemService.createDbItem(item);

     dbItemService.commit();

}

I think the following article might be of interest to you:

http://help.adobe.com/en_US/Flex/4.0/FlexTutorials/WSbde04e3d3e6474c4292a0331216558354b-8000.html#WSbde04e3d3e6474c4-10020e8112165e18e29-8000

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2010 Jul 19, 2010

Copy link to clipboard

Copied

LATEST

Thank you SO MUCH!!

You just saved my Moonday !

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines