You have seen how to retrieve data using the fill() method, and how to update data with an editable DataGrid. You will now create a small application to create and delete products.
Copy the file DMS_2.mxml from your Lesson21/start directory to driveroot/fds2/jrun4/servers/default/flex/flex2tfs. Return to Flex Builder, open that file, then run the DMS_2.mxml application.
Click on one of the products in the DataGrid, and you see that it populates the form and enables the Delete button.
This is the starting file for creating and deleting data with the Data Management Service. The file contains nothing you haven't already done in this book; the only FDS functionality used is the fill() method.
Locate the deleteProduct() function. As the first line of code in the function, use the deleteItem() method of the ds DataService object to delete the selectedItem from the DataGrid.
As the second line of code in the function, call the resetForm() method.
Run the application. Select a product and click the Delete button.
You see that the product is removed from the DataGrid. Refresh the page to be sure it is removed from the data store.
The product disappeared from the DataGrid upon deletion because the product was part of the ArrayCollection: it was removed from the ArrayCollection, and the DataGrid's dataProvider uses a binding to the DataGrid; hence, the DataGrid shows the latest and greatest data.
Locate the createProduct() function. As the first lines of code in the function, assign the product name and cost values from the form to the product variable. You will have to use the Number() function to convert the text gathered in the cost TextInput control to be able to assign it to the Number typed cost variable from the SmallProduct value object.