Exploring Flex

Flash Builder 4 – Data Centric Development (DCD) Configure Return Type

Posted by hneelu on June 11, 2009

We have covered the first wizard, Service Wizard. This wizard has lead to the successful creating of a service. We can see the service and its operation in the Data/Services view.
Example: I have imported a php file called MovieService** (code added at the bottom).
beforeCRT

To make this service useful I need to go through another wizard Configure Return Type.
This feature  provides GUI which enables user to test an operation of an existing service and view the returned data. User can also create appropriate entities/ custom data types which can later be used in their flex application. It enables code hinting, setting of datagrid columns on binding data to the operation etc.

The types of services which will be supported are:
1. Remote Object Service (AMF)
2. HTTP Service
3. Web Service

Entry Points

  • From Data/Services view toolbar:
    Select an operation in the service and click on the Configure Return Type icon in the toolbar.
    NOTE: All the operations are un-analyzed, since their return type is not known yet.

CRTToolbar

  • From Data/Services view Context Menu:
    Select an operation in the service and right click on it to open the context menu. From the context menu select option Configure Return Type


CRTContextMenu

  • From Bind to Data:
    Step 1: Drag and drop a datagrid on the design view.
    Step 2: Now, select an operation in the service wizard and drag and drop it on the datagrid. Bind to Data dialog opens.
    Step 3: Click on the Configure Return Type button (which is require to bind the data to a component).

BindToDataCRT

Configure Return Type for :

  1. AMF [How to use Configure Return Type for Remote Object (AMF) ie., for PHP, CF etc]
  2. Http Service [How to use Configure Return Type for HTTP service]
  3. Webservice. As soon as a web service is imported(using Service Wizard) the operations become analyzed*

Output:
In the above sample, I am using a PHP service MovieService.php . I have analyzed* the operation getAllItems(). See Example for AMF.

In the Data/Service view, the Service has a datatype MovieItem with its properties. Also, the operation becomes analyzed (See the icon).
CRTOutputSE

After the completion of the wizard VO(value objects) for the cutom datatypeMovieItem will be created under the src/services.
As you can see, VOs for  MovieType is created. Classes MovieItem.as, _Super_MovieItem.as are generated by the Flash Builder. There is another file _MovieItemEntityMetadata which contains metadata (properties maps, dependent maps etc)

I can write my own code in MovieItem.as which extends _Super_MovieItem.as

image2

Also, in the services folder [at the bottom] there is a link to the php service that I have imported. I can open the file in my own machine and make changes to the server code.

*Glossary

  • Analyzed operation = An Operation whose return type is known and VO for it has been created.

MovieService.php

<?php

class MovieService {

 private $connection;

 private function connect() {
 $this->connection = mysqli_connect("localhost",  "root",  "", "moviedb") or die(mysqli_connect_error());        
 }

 public function getAllItems() {
 $this->connect();
 $sql = "SELECT * FROM tmovies";

 $result = mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));

 $rows = array();
 while ($row = mysqli_fetch_object($result)) {
 $rows[] = $row;
 }

 mysqli_free_result($result);
 mysqli_close($this->connection);

 return $rows;       
 }

 public function getItem($itemID) {
 $this->connect();
 $itemID = mysqli_real_escape_string($this->connection, $itemID);
 $sql = "SELECT * FROM tmovies where ID=$itemID";

 $result = mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));

 $rows = array();
 while ($row = mysqli_fetch_object($result)) {
 $rows[] = $row;
 }

 mysqli_free_result($result);
 mysqli_close($this->connection);

 return $rows;
 }

 public function createItem($item) {
 $this->connect();
 $sql = "INSERT INTO tmovies (MovieName, Language, Summary, Actors, Reserved, MovieOwner, Type)
 VALUES ('$item->MovieName','$item->Language','$item->Summary','$item->Actors','$item->Reserved','$item->MovieOwner','$item->Type')";  

 mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));

 $autoid= mysqli_insert_id($this->connection);
 mysqli_close($this->connection);

 return $autoid;           
 }

 public function updateItem($item) {
 // TODO Auto-generated method stub

 }

 public function deleteItem($itemID) {
 $this->connect();
 $itemID = mysqli_real_escape_string($this->connection, $itemID);
 $sql = "DELETE FROM tmovies WHERE ID = $itemID";

 mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));

 mysqli_close($this->connection);            
 }

 public function count() {
 $this->connect();
 $sql = "SELECT * FROM tmovies";

 $result = mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));
 $rec_count = mysqli_num_rows($result);

 mysqli_free_result($result);
 mysqli_close($this->connection);

 return $rec_count;            
 }

 public function getItems_paged($startIndex, $numItems) {
 // TODO Auto-generated method stub
 }

}

?>

7 Responses to “Flash Builder 4 – Data Centric Development (DCD) Configure Return Type”

  1. […] Configure Return Type It test an operation of an existing service and view the returned data structure. It generates VOs which can we used in flex applications. [MORE] […]

  2. Harry said

    Is there a way to get object equivalence when returning data from Zend AMF?

    Ie in the example above lets add an arraycollection ‘theaters’ and have a property within the movie object of type theater

    So the Movie VO would be returned like this:
    Actors:String
    Id:int
    etc
    Theater:Object

    Now with Flash builder you can set the property Theater to be of type ‘Theater’ so you would then have an object of type ‘theater’ in the Movie object. This works great.

    However when you have a form for editing the movie you may have a

    When i’m in debug mode the ‘movie.theater’ and the related theater in the ‘theaters’ array collection looks almost identical except for the @XXXXXXX unique ID in flex.

    How can i get these to match up? so that ‘selectedItem’ works with object equivalence.

  3. BlogZeal.com for traffic schemes…

    […]Flash Builder 4 – Data Centric Development (DCD) Configure Return Type « Exploring Flex[…]…

  4. MAFRI said

    mafri…

    […]Flash Builder 4 – Data Centric Development (DCD) Configure Return Type « Exploring Flex[…]…

  5. domain name web hosting…

    […]Flash Builder 4 – Data Centric Development (DCD) Configure Return Type « Exploring Flex[…]…

  6. Thanks for your personal marvelous posting! I truly enjoyed
    reading it, you can be a great author. I will remember to bookmark your blog and will eventually come back in the future.
    I want to encourage you to ultimately continue your great posts,
    have a nice holiday weekend!

  7. Wonderful blog! I found it while searching on Yahoo News.
    Do you have any suggestions on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get there!
    Thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: