*** 6/8 UPDATE:  We have now added Flex Scaffolding in MyEclipse for Spring 8.6!!  Create an entire Spring Flex CRUD app in a matter of seconds.  Try it by downloading the 8.6 milestone. Check out the what's generated blog or the getting started video.

UPDATES: This blog has been updated for MyEclipse for Spring 8.5, Spring 3.0, and Flash Builder 4.  If you are looking for the previous version that includes the MyEclipse for Spring milestone, Spring 2.5, and Flex Builder 3, download the archived pdf.

In Part 1 of this example, I covered prerequisites, project creation and setup, and scaffolding in MyEclipse for Spring.  In Part 2, I will discuss adding the necessary pieces to get a Spring application Flex enabled through BlazeDS remoting.

This blog is divided into 2 parts:

web.xml

  1. Add the messagebroker servlet mapping: Insert the following code where the servlet mappings are defined.  This mapping is used by the Flex remoting object.
    <servlet-mapping>
        <servlet-name>ClassicFlexCars Servlet</servlet-name>
        <url-pattern>/messagebroker/*</url-pattern>
    </servlet-mapping>
  2. Add the flex context file: Find where the ClassicFlexCars Servlet is defined.  In the param-value element for the contextConfigLocation, add /WEB-INF/flex-servlet.xml.  So the resulting servlet block should look like:
    <servlet>
        <description>generated-servlet</description>
        <servlet-name>ClassicFlexCars Servlet</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/flex-servlet.xml,
              classpath:ClassicFlexCars-generated-web-context.xml,
              classpath:ClassicFlexCars-web-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

flex-servlet.xml

  1. Add a file, named flex-servlet.xml, to the ClassicFlexCars > WebRoot/WEB-INF folder with the following contents:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:flex="http://www.springframework.org/schema/flex"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/flex
     http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">        
    
         <flex:message-broker/>
    
         <!-- Expose the ProductService bean for BlazeDS remoting -->
         <flex:remoting-destination ref="ProductService" />
    
    </beans>

services-config.xml

  1. When adding the Flex Project Type, it adds a handful of files to the WebRoot/WEB-INF/flex folder.  Feel free to use whatever Flex provides.  However, to just get remoting up and running on a channel, all you need in the services-config.xml file is the following:
    <?xml version="1.0" encoding="UTF-8"?>
    <services-config>
    
        <services>
            <default-channels>
                <channel ref="my-amf"/>
            </default-channels>
        </services>
    
        <channels>
            <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint
           url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf"
           class="flex.messaging.endpoints.AMFEndpoint"/>
            </channel-definition>
        </channels>     
    </services-config>

    NOTE: Anytime this file is udpated or modified, you'll want to force a recompile of the swf file. These configurations are compiled into the flash file.

Add the spring-flex jar

  1. Add The following jar either through classpath containers or the WEB-INF/lib folder.  This jar can be found at the spring-flex download:
    • org.springframework.flex-1.0.3.RELEASE.jar

Flex UI - ClassicFlexCars.mxml

  1. To get a simple list view of the miniature cars, all that is needed is a remoting object defined, a data grid, and a button to load the data:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    
        <fx:Declarations>
            <s:RemoteObject id="ro" destination="ProductService" />
        </fx:Declarations>
    
        <s:VGroup horizontalAlign="left">
            <mx:AdvancedDataGrid dataProvider="{ro.loadProducts.lastResult}"/>
            <s:Button label="Get Cars" click="ro.loadProducts()"/>
        </s:VGroup>
    </s:Application>
    

Run it on BlazeDS

Add the BlazeDS tomcat server to the MyEclipse Server view by right-clicking the Servers pane and clicking Configure Server Connector.  Configure the Tomcat 6.x server to point to the BlazeDS tomcat directory.  Then add the ClassicFlexCars project to the server and run!  Browse to http://localhost:8400/ClassicFlexCars/ClassicFlexCars.html

References

< Page 1 | 2

Related Posts

Set Up and Use a Fake REST API with Angular Often, when developing Angular applications, you do not have the backing REST APIs ready for testing. To avoid having to digress into developing web services, or being blocked, waiting for your back end team to provide them, you can use JSON server to provide a "fake" API. This article will show you how to use Angular IDE and JSON Server to set up ...
Angular 5 Features Front-end developers, rejoice - after a short delay, the Angular 5 release is scheduled for October 23rd!Update (November 1st): It's finally here! After ten release candidates, Angular version 5.0.0, "pentagonal-donut", has been released.Update (October 31st): Well, we're still waiting for Angular version 5, and we're now at 5.0.0 RC 9 - but, I'm s...
Working with Java 9 in Eclipse Note: This blog was updated on October 11th, 2017 to reflect the release of Oxygen 1a which includes Java 9 support.The Java 9 GA release is just a few weeks old, and you can start developing with Java 9 in Eclipse, right now! All you need to do is download a suitable Oxygen 1a (4.7.1a) based distribution for both Java 9 and JUnit 5 support. Please...
Creating a Bus Fare Comparison App with Angular 4 ... In this Angular tutorial, you will learn how to create an app to compare bus fares. We will be using Angular IDE to create our application, which will fetch bus fare data using goibibo's web services.Creating a New Angular ProjectIn the new Angular project wizard, enter BusFareCompare as the project name. We used Angular CLI version 1.1.0, Node.js ...

Posted on Feb 16th 2010