7 March 2010
Some experience developing Flex applications will be helpful.
Beginning
LiveCycle Data Services ES2 is an important component for many companies migrating to a three-tier architecture for enterprise RIA development. The advanced Message Exchange Patterns (MEPs) it enables are unparalleled and very robust. This article is aimed at developers and distills the essential steps needed to set up model-driven development with LiveCycle Data Services ES2 and Flash Builder 4 beta 2.
In this tutorial, we'll share these steps to help you get started quickly and walk through building a simple application using a new technology that brings model-driven development to Flex developers.
Note: You may have heard this technology referred to as "Fiber" (also sometimes spelled "Fibre"). This was the internal project name and the technology is now available for public download.
Here are the steps you need to get started developing in Flash Builder 4 using the Adobe Application Modeling Plug-in.
Note: Selecting LiveCycle Data Services Web Application to use your own application server is slightly more complicated; the standalone option makes it easier to get started quickly.
<!-- begin rds
<servlet>
<servlet-name>RDSDispatchServlet</servlet-name>
<display-name>RDSDispatchServlet</display-name>
<servlet-class>flex.rds.server.servlet.FrontEndServlet</servlet-class>
<init-param>
<param-name>useAppserverSecurity</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping id="RDS_DISPATCH_MAPPING">
<servlet-name>RDSDispatchServlet</servlet-name>
<url-pattern>/CFIDE/main/ide.cfm</url-pattern>
</servlet-mapping>
end rds -->
<!-- begin rds to <!-- begin rds --> and change the last line from end rds --> to <!-- end rds -->. useAppserverSecurity value from true to false. The code should now look like this:<!-- begin rds -->
<servlet>
<servlet-name>RDSDispatchServlet</servlet-name>
<display-name>RDSDispatchServlet</display-name>
<servlet-class>flex.rds.server.servlet.FrontEndServlet</servlet-class>
<init-param>
<param-name>useAppserverSecurity</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping id="RDS_DISPATCH_MAPPING">
<servlet-name>RDSDispatchServlet</servlet-name>
<url-pattern>/CFIDE/main/ide.cfm</url-pattern>
</servlet-mapping>
<!-- end rds -->
This change removes application server security from RDSDispatchServlet so you can focus on writing code during development and not security issues. If you do not make this change, you'll see an error in Flash Builder 4 notifying you that the RDS server was successfully contacted, but your security credentials were invalid.
Note: When you have finished this tutorial, reset this parameter to true or disable RDSDispatchServlet to prevent unwanted access to the servlet, which could expose destination details on your server.
As the server starts up, you will see a line that shows the port that hsqldb is using. By default it is 9002 (see Figure 1). You'll use this information to configure the data source.
<Context privileged="true" antiResourceLocking="false" antiJARLocking="false" reloadable="true">
<!-- JOTM -->
<Transaction factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="60"/>
<Resource name="jdbc/ordersDB" type="javax.sql.DataSource"
driverClassName="org.hsqldb.jdbcDriver"
maxIdle="2" maxWait="5000"
url="jdbc:hsqldb:hsql://localhost:9002/ordersdb"
username="sa" password="" maxActive="4"/>
</Context>
There are two databases that you can use here: ordersdb and flexdemodb. The code above uses ordersdb.
Your environment is now set up and you're ready to start building your first model-driven Flex application.
Follow these steps to build a simple model-driven Flex application:
Root Folder: <TOMCAT_ROOT_DIRECTORY>/tomcat/webapps/lcds/
Root URL: http://localhost:8400/lcds
Context Root: lcds/ (Mac OS X) or /lcds (Windows)
Next, you must configure Remote Data Services (RDS) to enable the modeler plug-in to access the data source you just configured.
At this point, you should be able to expand LCDS (localhost) in the RDS Dataview panel and examine any of the database tables (see Figure 6). If you cannot connect to the server, right-click (or Control-Click) on LCDS (localhost), select RDS Configuration, and check your configuration settings. Common causes include security credentials (see the instructions on changing the useAppserverSecurity value in Setting up the environment) and a lack of data source mapping (see the instructions on adding a data source reference to
Note: The modeler plug-in stores data for the Design View layout in the FML file.
Note: You can use this same procedure to redeploy your model to the server if you later make changes to the model.
getAll() method onto the DataGrid component in Design view (see Figure 11). For each model deployed on the server, LiveCycle Data Services and Flash Builder 4 will generate methods that you can use to perform basic operations on the table represented by the model. The basic operations enable you to get all records (getAll), create a record (createProduct), update a record (updateProduct), and delete a record (deleteProduct). Apart from these methods, there are methods that you can use to filter records based on a value in a column of the table; in this case they are getByProductname and getByPrice, for example. You can also add custom methods to perform your own queries, but that is outside the scope of this article.
The DataGrid column headers will change to reflect the data returned by the call to the service. A link icon appears, indicating that the data is bound to the component.
It should fetch data from the server and display it in the DataGrid component (see Figure 12).
Of course, as a developer, you want more than just a simple display application. You're ready to add a form to enable CRUD capabilities.
getAll() method in the Data/Services tab and select Generate Form.
If you want, you can quit the application and rerun it to verify that the product you just added really was stored in the database.
Note: If you enter a non-integer price, you will notice that the price read back from the database is not exactly the same as what you entered. For example, I added a product priced at 7.3, and the price stored in the database was 7.300000190734. To understand why, examine the Price field in the RDS Dataview panel; it is defined as a FLOAT17, whereas in the actual form the price is defined as a Number. When you specify a price, save it to the database, and reload it, you are loading the FLOAT17 version of the data. This problem can be remedied fairly easily, but enumerating the steps is beyond the scope of this article.
Now that you know you can create a new record, you can make a few more changes to enable update and delete functionality as well.
<forms:ProductForm id="ProductForm1"
valueObject="{Product}" x="159" y="233">
x and y values may differ from those shown):<forms:ProductForm id="ProductForm1"
valueObject="{dataGrid.selectedItem as Product}" x="159" y="233">
This change will enable you to delete records and to make changes in the form and have them reflected in the data grid. The change is necessary because you generated the form from the data model, not from the data grid itself. As a result, the form was not automatically bound to the selected item of the data grid.
editable property to true.This will enable you to edit data directly in the data grid, without using the form.
Now when you select an item from the data grid, it will appear for editing in the form. Alternatively, you can edit data directly in the data grid. Any changes you make will be committed to the database when you click Save. Also, when an item is selected you can click Delete to remove it from the database.
That's it. You've built your first model-driven Flex application and added basic CRUD functionality with a bare minimum of coding.
For additional reading, see Model-driven Applications in Using LiveCycle Data Services. To access the LiveCycle Data Services ES Test Drive, use your browser to open
http://localhost:8400/lcds-samples/testdrive.htm.
Have fun unlocking the power of LiveCycle Data Services ES2 and Flash Builder 4.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License