*** 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.
A subtle but powerful side effect of having Spring generation capabilities with MyEclipse for Spring is the fact that creating Spring BlazeDS Flex apps is easier and faster than ever.
This example covers the basics to getting started with a spring-flex project in MyEclipse for Spring. The spring-flex framework uses Adobe's open source BlazeDS project, which is the remoting and messaging foundation for connecting a Flex-based front-end to Java back-end services. MyEclipse for Spring accelerates the Spring development by providing bootstrapping, scaffolding, and visual editing capabilities for all the necessary Spring configuration files code to support a ready to run Spring MVC application. The tutorial then goes on to tweak the MyEclipse for Spring generated configuration files to support Flex Remoting to produce a simple list view that calls the MyEclipse for Spring generated Spring service. Want to know more about MyEclipse for Spring, see the MyEclipse for Spring educational materials.
This blog is divided into 2 parts:
- Part 1: Setup & CRUD
- Part 2: Adding Spring Flex
What you'll need first
Before creating the project, there are a handful of items you'll need to setup your MyEclipse for Spring Flex Builder environment.
- Download BlazeDS: I downloaded the BlazeDS turnkey ready-to-use distribution, which comes with a version of tomcat. The BlazeDS installation guide was very helpful after the download.
- Get MyEclipse for Spring: GA is here!! Download a free trial now.
- Add Flash Builder 4: Download and install the Flash Builder 4 Plug-ins. During the installation process, a wizard pane will ask where to install the plugins. If you are using Mac OS, you may run into warnings about Carbon and Cocoa installations of eclipse and plug-ins not being provisioned. I clicked through those warnings, installed everything anyway, and was able to get through this sample app with no issues.
- References: Have the references section at the end of this blog handy. They are great resources for deeper understanding on any topic discussed here.
Create the Project & CRUD
There are a couple ways to create a Flex Project within MyEclipse for Spring. One approach is to separate the web project and flex project. A good reference for this approach can be found at Srinivas's blog. In this example, I'll use another approach which is to use one project since my Google search hasn't found a resource on how to do it:
- New MyEclipse Web Project: File > New > Web Project. Name it ClassicFlexCars. I'm using Java EE 5.0, plus all the defaults. Click Finish.
- Add the BlazeDS files: Srinivas's blog has a nice tip about bootstrapping MyEclipse Web Projects with BlaseDS. Basically, find the blazeds.war on your machine, and extract the contents to your project's WebRoot folder. (usually done outside of MyEclipse) Once extracted, refresh the ClassicFlexCars project and new files should exist, like the ones found in WEB-INF/flex/*
- Add Flex Project Type: Right-click the created ClassicFlexCars project, and select Add/Change Project Type > Add Flex Project Project Type. Modify the defaults as described in the following:
- Application server type: J2EE
- Use remote object access service: Checked
- Enable BlazeDS
- Click Next
- Root folder: (File path to the WebRoot folder of your project)
- RootURL: http://localhost:8400/ClassicFlexCars
- Context root: /ClassicFlexCars
- Output folder: WebRoot
- Click Validate Configuration.
- Click Finish.
- Clean up the Errors: You may get some errors in the Problems tab after adding the Flex Nature:
- An error about Cannot create HTML wrapper will appear. Right-click the error to resolve the issue. If you don't see the right-click context menu item, it can be resolved by right-clicking on the ClassicFlexCars project > Properties > Flex Compiler > un-check "Generate HTML wrapper file". Click OK. Then go back into the Project properties, Flex Compiler and check "Generate HTML wrapper file" to turn it on, and click Ok. You should then see a couple more files generated to your WebRoot, like ClassicFlexCars.html.
- Bootstrap: In order to add the Spring 3.0 libraries to the ClassicFlexCars project, right-click the project and select MyEclipse > Add Spring Runtime Dependencies...
- Click Next thru the first wizard pane to get to the Runtime Dependencies pane, and select the Spring 3.0 radio button. Click Finish.
- Scaffold: Let's create a ton of Spring app by using one existing table in a matter of seconds, shall we? If you aren't familiar with MyEclipse for Spring's CRUD Scaffolding capabilities, please take a look at the short How To on CRUD App Scaffolding for more details.
- Right-click the ClassicFlexCars project, and select MyEclipse > Scaffold Spring MVC CRUD Application from... This will pop up a wizard, which will walk you through scaffolding options.
- Check the Database Schema checkbox, and click Next
- Highlight the MyEclipse Derby database schema, click Next
- Choose the CLASSICCARS schema, and add the PRODUCT table over to the Scaffolding text area. Click Next.
- Type com.classicflexcars in the top package textbox. Uncheck the web layer generation. Click Finish or Next to view the remaining wizard panes.