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)"/>
<?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 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
...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
Copy link to clipboard
Copied
Thank you SO MUCH!!
You just saved my Moonday !