BlazeDS – ReferenceError: Error #1056

December 5th, 2008

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
package com.jeffdouglas;
 
public class MyObject {
 
    private int id;
    private String name;
 
    /**
     * @return the id
     */
    public int getId() {
        return id;
    }
    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }
    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
 
}

ActionScript Transfer Object – MyObjectTO

1
2
3
4
5
6
7
8
9
10
11
12
13
 
package com.jeffdouglas.model
{
 
    [Bindable]
    [RemoteClass(alias="com.jeffdouglas.MyObject")]
    public class MyObjectTO
    {
        public var Id:Number;
        public var Name:String;
    }
 
}

Flex Application – main.mxml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 
    <mx:RemoteObject id="blazeRo" destination="myDao"
        result="resultMyObject(event)"
        fault="faultHandler(event)"/>               
 
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.utils.ObjectUtil;
    import com.jeffdouglas.model.*;
 
    private function myObjectListener():void
    {
        blazeRo.getMyObject();
    }   
 
    private function resultMyObject(event:ResultEvent):void
    {
        var m:MyObjectTO = event.result as MyObjectTO;
        Alert.show(ObjectUtil.toString(m));
    }   
 
    private function faultHandler(event:FaultEvent):void
    {
        Alert.show(event.fault.faultString);
    }
    ]]>
    </mx:Script>
 
    <mx:Button label="Get MyObject" click="myObjectListener()"/>
 
</mx:Application>

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:

  1. I changed the members in my POJO from private to public (not a great solution, but it worked. I am still investigating this.)
  2. Made sure the members in both the POJO and TO were in the same order.
  3. 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.

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Categories: Flex, Java

Leave a comment

Comments Feed1 Comment

  1. Mike

    I’m sure you’ve noticed by now, but in case you haven’t, you don’t need to make the fields in the Java object public, it works just like JSTL for getters and setters, so pojo.getName() would be serialized to to.name, not to.Name. There is a rule that Blaze will persist either public fields or those with public getters AND setters, so no read-only properties from the Java side.

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)

Leave a comment

Feed

http://blog.jeffdouglas.com / BlazeDS – ReferenceError: Error #1056

WordPress Appliance - Powered by TurnKey Linux