Building Flex application for BlazeDS Remoting destinations using Flash Builder 4

Updated for Flash Builder 4 Beta 2 :)

Data Centric Development (DCD) in Flash Builder 4 allows developers to build Flex front end for Remoting destinations with just couple of clicks. Continue reading to see how Flash Builder is increasing J2EE developer productivity.

Set up BlazeDS

Download BlazeDS from this URL http://flexorg.wip3.adobe.com/blazeds/trunk/beta1/7548/blazeds-bin-4.0.0.7548.zip follow instructions at this URL to setup BlazeDS http://sujitreddyg.wordpress.com/2009/04/07/setting-up-blazeds/

Once BlazeDS is setup you need to expose the Java class as Remoting destination, visit this URL to know how to expose a Java class as Remoting destination http://sujitreddyg.wordpress.com/2008/01/14/invoking-java-methods-from-adobe-flex/

Once your Java class is exposed as Remoting destination using BlazeDS, follow steps below to build Flex application using Flash Builder 4.

In this sample we will expose SimpleCustomerService.Java as Remoting destination. SimpleCustomerService communicates with database and returns SimpleCustomer objects.

Setting up BlazeDS RDSDispatchServlet

After setting up BlazeDS, you have to enable RDSDisptachServlet, which is used by Flash Builder 4 to get destination details. This is disabled by default. It’s very simple all you have to do is to un-comment/add the Servlet mapping in the web.xml.

Copy the Servlet URL mapping and declaration for the RDSDispatchServlet from the web.xml in the blazeds.war file and add to your web application web.xml file. Else copy it from below

<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>

Install Flash Builder 4

Download and install Flash Builder 4 from this URL http://labs.adobe.com/technologies/flashbuilder4/

Creating new Flex project with BlazeDS server configurations

Create new Flex project

1

Create new Flex project from the File menu as shown in the image above.

Enter project details

2

In this screen:

  1. Enter project name
  2. set “Web (runs in Adobe Flash Player)” as the application type
  3. Set the Flex SDK to Flex 3.4
  4. Set the application server type to J2EE
  5. Select BlazeDS
  6. Click on Next to continue

Configure J2EE server settings

3

In this screen:

  1. Set the Root folder to the root folder of your web application with BlazeDS configured. Its C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\demo in this sample
  2. Set the Root URL to root URL of your BlazeDS enabled web application
  3. Set the Context root to context root of your BlazeDS enabled web application
  4. Leave the output folder to default value
  5. Click on validate configuration button
  6. Click finish to continue

Using DCD feature to connect to consume Remoting Service

DCD or Data-Centric Development is one of the advancements to the Flash Builder 4. Let’s see how this is making developers productive. In this sample we will see how to create a Flex application which consumes BlazeDS Remoting service. Same steps can be followed for LCDS Remoting services also.

Creating Service using DCD

4

  1. Select the Data/Services window shown in the image above. If this is not visible, select it from Window -> Data/Services
  2. Click on “Connect to Data/Service” in the Data/Services window
  3. Window as shown in the image below will be launched

5

Select BlazeDS and click on Next. Flash Builder will display a window asking for RDS credentials. Since we turned off security for our RDSServlet in the web.xml, select “No password required” and click on OK to continue.

6

Selecting Remoting destination

You can see that Flash Builder listed all destinations exposed in the screen below.

7

In this screen we are selecting the destination the newly created service should use. All destinations available will be displayed. Select a destination (SimpleCustomerServiceDestination in this sample) and click on Finish to continue.

Code for invoking the Remoting service will be generated, you can see the service and its operations (methods exposed by the Java class) being displayed in the “Data/Services” window and in the package explorer.

8

Flash Builder 4 introspects return types for the Java class methods and creates AS3 classes for any custom Java classes.

Binding data/service to UI controls

Switch design view and drag and drop a DataGrid component as shown in the image below.

9

In this screen:

  1. Switch to design view
  2. Change the Application layout to “vertical” using the properties panel
  3. Drag and drop a “DataGrid” from the “components” panel on to the design area
  4. Set the width and height properties of the “DataGrid” to 100%

Select the DataGrid. Right click on the DataGrid and select “Bind to Data …” as shown in the image below

10

A window as shown in the image below will be launched.

11

In this screen:

  1. We select a “New service call” because there are no existing services in the current application.
  2. Select the “SimpleCustomerServiceDestination”
  3. Select “getAllCustomers():SimpleCustomer[]” from the operations list
  4. Click OK

You can see the DataGrid with columns for added for properties of the SimpleCustomer class in the design view as shown in the image below.

12

Configuring DataGrid columns

Select the DataGrid. Right click on the DataGrid and select “Configure Columns …” as shown in the image below.

13

A window with options to configure the columns for the DataGrid will be launched as shown in the image below.

14

In this screen:

  1. Select “customerName” column and move it next to “customerId” column
  2. Click on OK
  3. Save and run the application

You can see application with data retrieved from the server and displayed in the DataGrid as shown in the image below.

15

More articles on how to use Flash Builder 4 – http://sujitreddyg.wordpress.com/flash-builder-4/

That’s it we have a Flex front end build for an existing Java class in just few minutes. Flash Builder 4 rocks :)

20 Responses to “Building Flex application for BlazeDS Remoting destinations using Flash Builder 4”

  1. Vivian Says:

    Good example. But I have a question suppose I am developing this same app in AIR what happens? The Blazeds setup form that we fill out at the beginning requires a root folder. AIR app can be running for a remote machine, how do we define the root folder for AIR app?

  2. MrVx23 Says:

    I’m using BlazeDS to call EJB3 beans on the server – there is a custom factory set up in remoting config for that. It seems that FB4 currently cannot handle such a configuration, because it says the destination is not available when I try binding a Flex service to a destination in the wizard. You briefly mention Java beans in your post – do you know of any way to make calling EJBs work in the new wizard?

  3. Thiagarajan Says:

    Hi

    I get this message on top of the services wizard

    Unable to authenticate on RDS server using current security information.

    How do I get past this
    I copied the RDS server jar to flex lib of the app and fixed the RDDispatchservlet info in web.xml also.

    Thanks
    Thiagu

  4. Sujit Reddy G Says:

    Hi Vivian,

    The root folder should be pointing to the server which your AIR application will send request to. Please check the article at the URL below for details.

    http://sujitreddyg.wordpress.com/2008/07/03/creating-blazeds-channels-at-runtime/

    Make sure you read the comments also :)

    Hope this helps.

  5. Sujit Reddy G Says:

    Hi MrVx23,

    I will check this and get back to you :)

  6. Sujit Reddy G Says:

    Hi Thiagarajan,

    Please set useAppserverSecurity param of the RDSDispatchServlet to false. I updated my post to reflect that. Thank you.

  7. Lurc Says:

    All works. As well as always, it is needed a bit to work a head.

  8. Bill Says:

    The BlazeDS download links no longer work. I assume you should download whatever is the BlazeDs 4 beta 1 build from http://opensource.adobe.com/wiki/display/blazeds/download+blazeds+trunk

  9. Sujit Reddy G Says:

    Hi Bill,

    Thanks for pointing this out, updated the post with correct URL :)

  10. Phil Says:

    Do you know of a way to use a WTP-enabled project without it breaking all of the new data-centric development features? If you create such a project, FB 4 beta 1 gets confused about adding data sources. Without such a project, there’s no apparent way to have the server-side Java code and the client-side Flex code in the same project.

  11. Suresh Says:

    I got this error while connecting to the data service after giving the name for the same and choosing finish

    aSome error occurred while attempting to write to the file.
    Error while generating value object classes : java.lang.NullPointerException

  12. Suresh Says:

    Its success now, i tried other one its successful, wonder ful thanks a lot Sujit all ur posts are excellent.

    How to write class files for new databases please help

  13. Sujit Reddy G Says:

    Hi Suresh,

    Where do you want to create this database ? on the server or local system using AIR ?

  14. Simon Says:

    hey sujit,
    i’ve got a problem with dcd and blazeds.

    in the panel “data services” I only get the choice between HTTP and WebService.
    via the main menu “data->connect to BlazeDS” I get the wizard window which is empty. It shows neither the caption nor any content. Just the cancel and finish buttons which both don’t work. The only chance to go back is the “x”.

    What I’m I doing wrong?
    I played around with the lcds3 and fiber (model driven approach) and everything was great.

    Facts:
    BlazeDS: latest Version (blazeds-turnkey-4.0.0.9845 and also blazeds-turnkey-4.0.0.9369)
    Flash Builder: latest version from pre-release (build 246332)
    Os: Mac
    Server type as J2EE/BlazeDS
    and RDS is setup and working

    Any ideas?
    Thanx in advance
    Simon

  15. Sujit Reddy G Says:

    Hi Simon,

    Thank you for bringing this to our notice. I don’t think you are doing anything wrong, I remember facing the same problem :) Did you try restarting Flash Builder ? Can you please share Flash Builder error logs. Thank you.

  16. Kris Says:

    I’m getting this error from Tomcat 6.0.20 after following your instructions and using the correct version of BlazeDS:

    [BlazeDS]LCDS java introspector servlet initializing
    [BlazeDS]Unable to load RDS initClass (ClassNotFoundException): flex.rds.server.lcds.servlet.LCDSRDSServletInit

    I can’t figure out why/where this servlet is being referenced, but it would appear that the error is keeping RDS from starting up properly. Do you have any idea what could be causing this? I’ve search the bug DB with no luck and no mention of the problem anywhere else.

    Thanks!

  17. Perroud J-P Says:

    Hi,
    With beta 2, I can no longer import a service with BlazeDS.
    Here is the error:
    ERROR: XML parse error: Error on line 1 of document: cvc-elt.1: Can not find the declaration of element ‘model’. Nested exception: Can not find the declaration of element ‘model’.
    Thank you for your help.
    JPP

  18. aaron Says:

    ERROR: XML parse error: Error on line 1 of document: cvc-elt.1: Can not find the declaration of element ‘model’. Nested exception: Can not find the declaration of element ‘model’.

    Me also face a same problem. anyone can help please

  19. zoltane Says:

    aaron, using BlazeDS v4.0.0.11030 nightly build will solve your problem.

    Zoltan

  20. Chris Alford Says:

    Thanks for your article, very useful example. I have been struggling with BlazeDS , eclipse, FB beta 2 but am having a fair amount of success building an app drawing data from MS SQL and MySQL servers with RDO’s. But I still can’t solve the XML parse error cvc-elt etc. even though am using v4.0.0.11221. Doing a bit of research this is an error which has been re-occuring for a number of years. As a side line I had a great bug. It only happened on my 10.6 Mac, and when I transfered the files to my scabby old p.c. I saw the bug in action. It appeared that the MS SQL database driver was loading and then ? was loading any file with a similar name, e.g. the .mssql.jar hidden file which the Mac file system creates. The strangest part of this bug is that it disappeared once I totally corrupted my BlazeDS installation trying to fix the XML problem :)
    If anyone has a definite answer to the XML problem I would like to know.
    Regards Chris

Leave a Reply