Building database-driven Flex applications without writing (Client- or server-side) code
One question that developers often ask when they see Flex for the first time is: “how do I write a database application?”
The answer to this question is typically: You use an HTTPService, WebService, or RemoteObject to connect to a server-side component that provides an API to manipulate your data. This approach provides infinite possibilities, but it makes the assumption that you already have that entire backend infrastructure in place. If you don’t, and all you want to do is build a rapid prototype or a simple application, this might look like a lot of work.
In addition to the RPC services mentioned above, the Flex Data Management Services (FDMS) provide a virtually code-free approach to synchronize data between the client application and the middle-tier. That takes care of 50% of our challenge: no data synchronization code to write at the client-side.
FDMS also provides a pluggable adapter and assembler architecture to handle changes at the server-side. As an example of writing a generic assembler, I built a simple JDBC assembler that allows you to develop rapid prototypes and basic database-driven applications without writing a single line of server-side code. All you need to do is specify the database connection information and the table you want to work with in data-management-config.xml.
This assembler is by no means a full featured solution, but it shows the power and flexibility of the FDMS architecture: you could easily extend its capabilities, or build other generic assemblers for existing persistence solutions (a Hibernate assembler is already shipping with the product).
The point is that if FDMS provides a solid architecture to handle the most complex persistence scenarios (with virtually no data synchronization code at the client side), with the addition of specialized assemblers, it can also provide simple solutions to simple use cases, significantly improve your productivity, and deliver end-to-end code-free persistence.
Installing the SimpleJDBCAssembler:
- To use the SimpleJDBCAssembler, you need to install the Flex Data Services. If you haven’t already done so, you can download the Flex Data Services here, and follow the installation instructions.
- Download jdbcassembler.zip here and expand it in your root directory (the files will be unzipped in a directory called jdbcassembler)
- Copy SimpleJDBCAssembler.class in {context-root}\WEB-INF\classes\flex\samples\assemblers. For example, if you installed the integrated server, copy SimpleJDBCAssembler.class in \fds\jrun4\servers\default\samples\WEB-INF\classes\flex\samples\assemblers.
Running the sample application:
- Copy the \jdbcdemo directory in the context root of your web application. For example, if you installed the integrated server, copy the \jdbcdemo directory in \fds\jrun4\servers\default\samples.
- Open {context-root}\WEB-INF\flex\data-management-config.xml and add the following destination:
- This example uses an embedded HSQLDB database. Make sure hsqldb.jar is available in the classpath of your web application. For example in {context-root}\WEB-INF\lib. If you are using another database, make sure the JDBC driver for that database is in the classpath of your web application.
- Start the server
- Access http://localhost:8700/samples/jdbcdemo/simpleclient.mxml. (Change the port number and the context root as appropriate). This is a basic client built with just a few lines of code. You can edit the data inside the datagrid.
- Access http://localhost:8700/samples/jdbcdemo/app.mxml. (Change the port number and the context root as appropriate). This is a slightly more sophisticated client. You edit data in a separate form.
<destination id="jdbc-product">
<adapter ref="java-dao" />
<properties>
<source>flex.samples.assemblers.SimpleJDBCAssembler</source>
<scope>application</scope>
<metadata>
<identity property="PRODUCT_ID"/>
</metadata>
<database>
<driver>org.hsqldb.jdbcDriver</driver>
<url>jdbc:hsqldb:/jdbcassembler/db/flexdemo</url>
<table>product</table>
<autoincrement>true</autoincrement>
</database>
</properties>
</destination>
Also notice that changes are pushed in real time to all the clients connected to a destination. For example, open the application in two browser sessions, change some data in one session, and notice that the changes are automatically pushed to the second session.
Comments
51 Responses to “Building database-driven Flex applications without writing (Client- or server-side) code”
Leave a Reply









Yeah, right! But how can I “run” the flexdemo.script to create the needed tables?
Thanks!
You don’t have to run that script. flexdemo.script “is” the flexdemo database. That’s how HSQLDB stores a database.
Thanks, Christophe!
But I’m getting a SQL table not found exception. Here goes the stack trace:
java.sql.SQLException: Table not found in statement [SELECT * FROM product]
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.executeQuery(Unknown Source)
at flex.samples.assemblers.SimpleJDBCAssembler.fill(SimpleJDBCAssembler.
java:82)
at
I would appreciate if you can help me. Thanks again!
Beck,
In data-management-config.xml can you specify
jdbc:hsqldb:/jdbcassembler/db/flexdemo for the database URL? Let me know how that works.
Thanks,
Christophe
The same error, Christophe!
Here is my data-management-config.xml.
flex.samples.assemblers.SimpleJDBCAssembler
application
org.hsqldb.jdbcDriver
jdbc:hsqldb:/jdbcassembler/db/flexdemo
product
true
Did you unzip jdbcassembler in your root directory? Basically the jdbc URL is a path to your database (flexdemo.script). So jdbc:hsqldb:/jdbcassembler/db/flexdemo assumes that you have the fully populated flexdemo.script in:\jdbcassembler\db\flexdemo.
I too could not get the hsqldb going (I could if I used a absolute path eg: c:\…etc. So i ported it to MySQL. Anyone else doing this or planning to use this great assembler with MySQL a word of advice, I found a little got ya. When you specify the connection string in data-managent.config be sure to use & instead of & when specifying you url eg:
jdbc:mysql://localhost/flexdemo?user=flexdemo&password=flexdemo
instead of
jdbc:mysql://localhost/flexdemo?user=flexdemo&password=flexdemo
otherwise you will get a unfriendly message like:
Configuration error encountered on line 230, column 72: ‘The reference to entity “password” must end with the ‘;’ delimiter.’
if you don´t do this.
Cheers
dd
I’m a java convert from .Net….can I get the .java file for this demo?
Thanks for the great sample!!!
I really like your site, keep up the good work.
This is a wonderful blog I missed all these days.
Getting the same error as Beck above, and I have everything in the right directories (I think)
Hi Christophe,
the link below has a lot of good examples in flex 2 charts, i think but none of them work
http://weblogs.macromedia.com/flex_samples/charts_explorer/explorer.html
could you suggest a similar working site of flex 2 examples
regards
Arthur,
You’re right - these were working the last time I looked at them a few weeks ago…
Anyway, there is a different group of chart samples at http://www.quietlyscheming.com/blog/charts/chart-sampler/. Click the “Charting Sampler” link for the demos. You can check out the code for all of them as well.
Enjoy!
[RPC Fault faultString="No destination 'jdbc-product' exists in service flex.data.DataService" faultCode="Server.Processing" faultDetail="null"]
at mx.data::ConcreteDataService/http://www.adobe.com/2006/flex/mx/internal::dispatchFaultEvent()
at ::DataListRequestResponder/fault()
at mx.rpc::AsyncRequest/fault()
at ::NetConnectionMessageResponder/NetConnectionChannel.as$33:NetConnectionMessageResponder::statusHandler()
at mx.messaging::MessageResponder/status()
Hi
Get the above error when I start the application
can you please help,I am new to this stuff
thanks
girish
Christophe - awesome example! I have replicated the product table in Oracle and tried to modify the data-management-config.xml but am getting Channel.Connect.Failure.
Attempting something like this:
flex.samples.assemblers.SimpleJDBCAssembler
application
oracle.jdbc.driver.OracleDriver
jdbc:oracle:thin:uid/pwd@myserver.domain.com:1526:schema
product
true
I’m I missing something? Can you post an example or point me to one?
Thanks!
hi..
i found ur sample interesting but can u revert me or post an sample program for connecting flex with oracle table as i am finding it very difficult to get the solution for this.
thanks
dinesh
hi!
How can I listener the message users are chatting?
I need to store then
its a good example. but could you help me with this exception that i get on load??
[RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error undefined url:'rtmp://localhost:2037'"]
at mx.data::ConcreteDataService/http://www.adobe.com/2006/flex/mx/internal::dispatchFaultEvent()
at ::DataListRequestResponder/fault()
at mx.rpc::AsyncRequest/fault()
at mx.messaging::ChannelSet/::faultPendingSends()
at mx.messaging::ChannelSet/channelFaultHandler()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.messaging::Channel/mx.messaging:Channel::connectFailed()
at mx.messaging.channels::PollingChannel/mx.messaging.channels:PollingChannel::connectFailed()
at mx.messaging.channels::RTMPChannel/mx.messaging.channels:RTMPChannel::statusHandler()
Hi Christophe,
I stumbled upon this blog when I was trying to find a solution to an error i’m encountering while using FDS.
Basically i’m modifying the Contact Manager FDS sample to use a ready SQL database but just replacing the MSAccess database with SQL DB throws a wierd error.
I can get my ArrayCollection populated with data from the SQL server but each object is empty.
My Java wrapper lists all the objects correctly before passing to Flex but somewhere they just break and come in Flex as empty objects.
This only happens when using an SQL DB and not with an MS Access DB…everything else stays the same.
The exact error it throws is
The fill method with parameters ‘[Ljava.lang.Object;’ and destination ‘contacts’ returned null.
I would appreciate if you can help me. Thanks!
adf
Arunkumar…
I had the same problem. I solved it by creating the directory path exactly as specified: for example, mine is:
\fds2\jrun4\servers\default\samples\WEB-INF\classes\flex\samples\assemblers
(note that I needed to add a “flex” directory with “samples” and “assemblers” subdirectories)
After restarting the Integrated Flex Server, it worked.
Good luck!
Great example. What about creating an application that talks to a mysql database on a shared server web hosting plan?
Is there really that much code involved in writing a php script to modify and update tables?
First it worked fine and the for some unknown reason
I started to get an SQL table not found exception.
Any ideas, help, suggestions??
How to connect to MS-SQL database and to retrive data ie a row and display it in the flex application please provide the code for the java dao and the flex part.
I m new to flex
plz help me out!!!!
Hi
I am getting following error. I am using Mysql as database and Jrun as application server.
Could you please let me know How do I resolve these errors
[RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error undefined url:'rtmp://localhost:2037'"]
at mx.data::ConcreteDataService/http://www.adobe.com/2006/flex/mx/internal::dispatchFaultEvent()
at ::DataListRequestResponder/fault()
at mx.rpc::AsyncRequest/fault()
at mx.messaging::ChannelSet/::faultPendingSends()
at mx.messaging::ChannelSet/channelFaultHandler()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.messaging::Channel/mx.messaging:Channel::connectFailed()
at mx.messaging.channels::PollingChannel/mx.messaging.channels:PollingChannel::connectFailed()
at mx.messaging.channels::RTMPChannel/mx.messaging.channels:RTMPChannel::statusHandler()
Hello! Good Site! Thanks you! jdrvqjjhrqtfrm
hi
Plz send me sample examples of database connectivity with oracle/db2 using flex>also send me the steps for connectivity and the required components like data service
my email
shrinivas.sontakke@gmail.com
Does anyone know a solution to Arunkumar or Vinay’s problem? I am also facing the same issue in tomcat.
Regards,
Karthik.
hi
Plz send me sample examples of database connectivity with oracle/db2 using flex>also send me the steps for connectivity and the required components like data service asap so that it will help me a lot
my email
anitha.govindaswamy@wipro.com
08/06 11:07:38 user MessageBrokerServlet: init
08/06 11:07:39 error Could not pre-load servlet: MessageBrokerServlet[1]flex.messaging.MessageException: Cannot create class of type ‘test.SampleServ
ice’. Type ‘test.SampleService’ not found.
at flex.messaging.util.ClassUtil.createClass(ClassUtil.java:57)
at flex.messaging.factories.JavaFactory$JavaFactoryInstance.getInstanceClass(JavaFactory.java:244)
at flex.messaging.factories.JavaFactory$JavaFactoryInstance.createInstance(JavaFactory.java:251)
at flex.messaging.factories.JavaFactory.createFactoryInstance(JavaFactory.java:93)
at flex.messaging.FactoryDestination.getFactoryInstance(FactoryDestination.java:76)
at flex.messaging.services.remoting.adapters.JavaAdapter.validateInstanceSettings(JavaAdapter.java:254)
at flex.messaging.services.remoting.adapters.JavaAdapter.initialize(JavaAdapter.java:99)
at flex.messaging.services.AbstractService.start(AbstractService.java:206)
at flex.messaging.MessageBroker.startServices(MessageBroker.java:503)
at flex.messaging.MessageBroker.start(MessageBroker.java:181)
at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:107)
at jrun.servlet.WebApplicationService.loadServlet(WebApplicationService.java:1200)
at jrun.servlet.WebApplicationService.preloadServlets(WebApplicationService.java:791)
at jrun.servlet.WebApplicationService.postStart(WebApplicationService.java:293)
at jrun.deployment.DeployerService.initModules(DeployerService.java:711)
at jrun.deployment.DeployerService.createWatchedDeployment(DeployerService.java:242)
at jrun.deployment.DeployerService.deploy(DeployerService.java:430)
at jrun.deployment.DeployerService.checkWatchedDirectories(DeployerService.java:179)
at jrun.deployment.DeployerService.run(DeployerService.java:891)
at jrunx.scheduler.SchedulerService.invokeRunnable(SchedulerService.java:230)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
[0]flex.messaging.config.ConfigurationException: Error instantiating application scoped instance of type ‘test.SampleService’ for destination ’sampleService’.
at flex.messaging.factories.JavaFactory.createFactoryInstance(JavaFactory.java:117)
at flex.messaging.FactoryDestination.getFactoryInstance(FactoryDestination.java:76)
at flex.messaging.services.remoting.adapters.JavaAdapter.validateInstanceSettings(JavaAdapter.java:254)
at flex.messaging.services.remoting.adapters.JavaAdapter.initialize(JavaAdapter.java:99)
at flex.messaging.services.AbstractService.start(AbstractService.java:206)
at flex.messaging.MessageBroker.startServices(MessageBroker.java:503)
at flex.messaging.MessageBroker.start(MessageBroker.java:181)
at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:107)
at jrun.servlet.WebApplicationService.loadServlet(WebApplicationService.java:1200)
at jrun.servlet.WebApplicationService.preloadServlets(WebApplicationService.java:791)
at jrun.servlet.WebApplicationService.postStart(WebApplicationService.java:293)
at jrun.deployment.DeployerService.initModules(DeployerService.java:711)
at jrun.deployment.DeployerService.createWatchedDeployment(DeployerService.java:242)
at jrun.deployment.DeployerService.deploy(DeployerService.java:430)
at jrun.deployment.DeployerService.checkWatchedDirectories(DeployerService.java:179)
at jrun.deployment.DeployerService.run(DeployerService.java:891)
at jrunx.scheduler.SchedulerService.invokeRunnable(SchedulerService.java:230)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
08/06 11:07:39 user FlexSwfServlet: init
08/06 11:07:39 user FlexInternalServlet: init
Any solution for the above problems?
Iam facing this problem when i use RPC.
hi guys i am new i am using struts with flex i got same error as Arunkumar or Vinay’s problem? please help
Hi Guys there could anyone help us(Arunkumar, Vinay, Karthik and myself) with a solution to solve “Channel.Connect.Failed” error. I am working on a crucial prototyping with short deadline. Given below are the steps I have followed installing
1. Install WTP 1.5.3(Eclipse)
2. Install Flex Builder 2.0 Plugin
3. Install Flex Builder 2.0.1 Update
4. Install Flex Builder 2 Hotfix 2
5. Update Flex Builder with Hotfix 3
6. Install Peter Martin FDS Plugin
7. Configure WTP VM param
8. Installation of LCDS 2.5
8. Configure LCDS in WTP
9. Configure Tomcat in WTP
10. Create a sample LCDS Project
Your reply is most awaited !!!
Thanks in advance
David
Hi Guys there could anyone help us(Arunkumar, Vinay, Karthik and myself) with a solution to solve “Channel.Connect.Failed” error. I am working on a crucial prototyping with short deadline. Given below are the steps I have followed installing
1. Install WTP 1.5.3(Eclipse)
2. Install Flex Builder 2.0 Plugin
3. Install Flex Builder 2.0.1 Update
4. Install Flex Builder 2 Hotfix 2
5. Update Flex Builder with Hotfix 3
6. Install Peter Martin FDS Plugin
7. Configure WTP VM param
8. Installation of LCDS 2.5
8. Configure LCDS in WTP
9. Configure Tomcat in WTP
10. Create a sample LCDS Project
Your reply is most awaited !!!
Thanks in advance
David
david.wilfred@gft.com
I encountered the same error log while trying the same kind of sample app, to get rid of it, I just had to restart my jboss server.
I am just trying to work on a sample application using Eclipse,Flex Builder Plugin,LCDS 2.5 and Tomcat.
Can anyone provide a PDF or Link which can guide me through steps
David
david.wilfred@gft.com
I am just trying to work on a sample application using Eclipse,Flex Builder Plugin,LCDS 2.5 and Tomcat using MYSQL as database.
Can anyone provide a PDF or Link which can guide me through steps
David
david.wilfred@gft.com
Now that FDS have been rolled into LiveCycle Data Services, AND that AIR/Flex 3 is in beta, it would be great to have an update to this article/primer on db connectivity w/Flex. If a more current article exists, could someone point me to it?
thx
hi guys
i am getting the following error wen i invoke a java arraylist using ” mx:RemoteObject ” tag to dataProvider of datagrid in flex .
[RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error undefined url:'rtmp://10.21.160.235:2037'"]
any sample examples for mx:RemoteObject is apreciated
u can reply to my email id
thanks
kandasami raja.c
kandaraja@gmail.com
Channel.Connect.Failed
I was getting this error, that was because I didn’t extract the .zip on c:\, then the database was on the wrong place.
If you see the data-management-config.xml in the database section we had the following line:
jdbc:hsqldb:/jdbcassembler/db/flexdemo
/jdbcassembler/db/flexdemo -> it’s the path to the database, and the base path is c:\ in windows (note that this path is NOT relative to the CONTEXT ROOT!!), you can adjust this to another directory if you wish.
I have also tested with the fds-tomcat instead of jrun4 sucessfully.
i am new user to the flex i want to know how to connect my application with the database with the help of java (j2ee) codding and i am not using the
i am not using the flex data service
i have the ibm web sphere application developer installed in my system, as well as flex also
please give me some solution to tackle with this issue
it gives an error jdbc-product must required a channel
do you know a good site that will have flex and sql server integration?
thanks
aleks
hiiii iam new to this flex.. and iam not able to under the above process said by “Christophe Coenraets”.. wht athis content-root refers to??
i want to connect to oracle database..
can any one xplain me clearly plzzzz
hi guys
i am getting the following error when i acces my application on live ip
[RPC Fault faultString=”Send failed” faultCode=”Client.Error.MessageSend” faultDetail=”Channel.Connect.Failed error undefined url:’rtmp://203.215.163.72:8080:2037′”]
while my application is working properly on LAN our internal loacal ips like 192.168.200.24 i can access that properly. Can any body tell my if there is any settings in XML or any secuirty policy
u can reply to my email id
zaffargachal@gmail.com
thanks
Zaffar ali
ya mm is hot aparently
y MUMS? COS THEY ROCK
Is there any “simple” way to get notified (and the clients updated) when the data changes in the datasource? Example: I have FLEX client app opened in 3 different machines. When data is changed in the (editable) datagrid, Livecycle DS takes care of updating the clients. Datasource is MS SQL server table. Now, if I change the data directly on that SQL table, nothing happens in the FLEX apps. This is important in environments where different technologies (not only Flex apps) interact with a data source. In my case we have a few different financial applications dealing with different sets of data. Any clue on how to deal with that? Updating the clients when changes in the SQL table occur? (without using fill commands polled every few seconds?).
Hi Fernando,
If the data is manipulated directly in the database without the DS then there is no way this change can be pushed to the clients. Only option would be for the clients to poll the data on a regular interval. Other option that I can think of is to have an insert/update trigger on the table and as part of trigger management somehow notify DS service.
Thanks,
Sanjib
Hi,
Will this tool serve the purpose of integrating the informix database with a Websphere Message broker and can function like JDBC adapter.
thanks.
hi we are planned to take seminar About the FLEx topic can you give the procedure to do the application(Sample Project) in Flex 3.0