I have been doing Flash Remoting with Flex and ColdFusion for a number of years but wanted to do something with a pure Java solution. I decided to setup BlazeDS (Adobe's open source server-based Java remoting and web messaging technology) on my EC2 instance for fun.
I found a great tutorial ("Getting started with BlazeDS") from Christopher Coenraets that walks you through the entire process. I downloaded the BlazeDS war, dropped it into Tomcat, configured my destinations in the config file and created my Java DAOs and POJOs. I was up and running in less than an hour and developing a POC application. The Java part went along smoothly but I ran into a small snag with my Flex app.
I wrote a small Flex app that calls the DAOs as RemoteObjects and returns ActionScript TransferObject from my POJO instances. Here is my initial code:
POJO - MyObject.java
ActionScript Transfer Object - MyObjectTO
Flex Application - main.mxml
My problem was that the TO was not being populated by the POJO correctly. All of the members were null in the debugger. I looked in Eclipse and found the following error message:
ReferenceError: Error #1056: Cannot create property id on com.jeffdouglas.model.MyObjectTO. ReferenceError: Error #1056: Cannot create property name on com.jeffdouglas.model.MyObjectTO.
Here’s how I fixed the problem:
- I changed the members in my POJO from private to public (not a great solution, but it worked. I am still investigating this.)
- Made sure the members in both the POJO and TO were in the same order.
- Made sure the member names in the POJO and TO were the same case. I had used "Name" and "Id" in the TO and "name" and "id" in the POJO.
After these changes were made the POC worked like a champ and the development resumed.