Copyright © 2011 Skyway Software
Table of Contents
One of the goals of MyEclipse for Spring (ME4S) is to help developers write less code from scratch and use code generation more broadly, and ME4S offers the richest set of code generation options available anywhere. ME4S can generate software components for Spring MVC, Spring Web Flow, Spring Security, REST, JAX-WS, Adobe Flex, Google Web Toolkit (GWT), JPA, DAO and JSF 2.0/Primefaces. As an alternative to writing software components from scratch, ME4S helps developers generate software components that are specific to their project. In many cases the software components may be used as-is, or they may be used as a starting point for further development. Furthermore the developer can edit the ME4S templates to further customize how the software components are generated.
Scaffolding refers to the superset of ME4S's broad code generation functions, from generating a specific set of requested software components to generating fully implemented ready-to-run applications. Besides the obvious benefits of reducing application development effort and sparing developers from some of the chores of development, scaffolding is also frequently used for rapidly developing functional prototypes, learning new technologies, and application modernization projects. The ability to quickly generate a full application is very beneficial to prototyping because you can iterate on a domain model and regenerate a functional prototype in minutes. The prototype can be used with business analysts as a tool for elaborating requirements and as the starting point for development. ME4S helps many developers learn new technologies by generating contextual reference projects, which are personalized projects that are based on their own data model. This is a considerably better approach than hunting for sample projects that are often incomplete, don't follow modern best practices, and are based on trivial data models. ME4S can also be used to jumpstart an application modernization effort by leveraging application artifacts from the current system for generating a significant portion of the application components for the new system.
The objective of this tutorial is to walk you through the generation of software components for Adobe Flex and Spring-Flex. Adobe Flex is a free open source framework for building expressive web applications that deploy consistently on all major browsers, desktops, and operating systems by leveraging the Adobe® Flash® Player and Adobe AIR® runtimes. Spring-Flex BlazeDS Integration is a top-level Spring project, with the purpose of making it easier to integrate Adobe Flex applications with Spring-based sofware components. In addition to generating the Adobe Flex and Spring-Flex software components, this tutorial will also generate the software components for the service, domain, and data access layers. This will result in a fully implemented ready-to-run Adobe Flex application that can be immediately used for validating and testing the generated Adobe Flex components, and it will also serve a reference implementation for how the generated Adobe Flex components integrate with the other components of an application using Spring-Flex.
MyEclipse for Spring uses the Create-Read-Update-Delete (CRUD) application pattern for generating applications that allows the end-user to manage application data. While CRUD isn't the only application pattern, it's a fairly typical application pattern. While not all web applications are satisfied solely by the CRUD application pattern, developers find that the resulting generated application artifacts lend themselves to being easily re-used, customized and extended. CRUD applications are tied to an application domain model that is used as the input into the scaffolding engine. The domain model can exist in many forms, and the MyEclipse for Spring scaffolding functionality supports the use of Java beans, JPA entities, or database tables as inputs.
This tutorial is going to walk you through producing a
ready-to-run Spring Flex application that implements the CRUD application
pattern for a domain model.
Domain model: EMPLOYEE and OFFICE tables from the MyEclipse Derby database.
Target Container: MyEclipse Tomcat
Target Database: MyEclipse Derby
MyEclipse for Spring will be used to generate the entire application within a matter of minutes that includes:
A JPA entity corresponding to domain models (EMPLOYEE and OFFICE)
DAOs to managing the JPA entity,
Finder methods (JPA named queries) in the DAO based on domain model fields,
Services with fully implemented CRUD operations for managing the domain model,
All the necessary Spring annotations and configuration files for a Spring Flex app,
JUnits for every Service and Controller,
SpringSource certified code and configuration files,
Spring Framework 3.0 (Spring 2.5 optional)
Generated Flex 4.0 mxml (Flex 3.5 optional)
Spring BlazeDS Integration 1.0.3
Out of the box Adobe Flex 4.0 open source SDK and ant script using the mxmlc compiler that generates the swf file into the webroot,
An mxml Default Application with separate mxml Forms and Grids for CRUD operations and relationships,
A flex_src/assets folder with CSS and images. Uses Embed statements and common Flex styles like backgroundGradientAlphas, up-skin, over-skin, down-skin
Use of the DataGrid with dataProvider to render results from the Server,
Implementation of a TabNavigator to show the CRUD operations and relationships,
A RemoteObject in separate mxml applications implemented by creating Operations,
An Alert Form validation using StringValidator, NumberValidator, the Validator.validateAll method and ValidationResultEvent adhering to the General guidelines for validation,
Asterisks on required fields with the required attribute on the FormItem,
Use of the Accordion control to show child relationships,
PopUpManager implementation when deleting objects or reporting errors,
Editable DataGrid control for the child in One-to-Many or Many-toMany relationships,
DateFormatter controls used to format Date and Time fields in forms and inside editable data grids,
Use of the Dissolve alternative to fading text,
Creates Bindable RemoteClass domain objects with relationships, and
Code which follows spring-flex-testdrive conventions including, an Event driven action script architecture for created, updated, and deleted objects. Plus, a compilation of best practices found within the Flex community and recommended to us by Flex experts.
The prerequisites needed to complete this tutorial are:
Download MyEclipse for Spring 10.0
OPTIONAL: Flash Builder plugins 4. As noted above, MyEclipse for Spring 8.6 comes packaged with the open source Flex 3 SDK, which is used to compile the Flex development assets into a flash file.
Create a MyEclipse Web Project (or Eclipse Dynamic Web Project) called EmployeesApp
NOTE: If you are using Flash Builder and want to use a Flex Project, please take a look at the following forum post which helps set up the project for scaffolding: http://www.myeclipseide.com/PNphpBB2-viewtopic-t-25828.html.
It's now time to generate all the software components and configuration files required to implement the CRUD application.
Right-click on the EmployeesApp project, and choose MyEclipse > Scaffold Spring CRUD Application from...
The first step is to select the type of artifact you want to scaffold from. As mentioned in the tutorial introduction there are a variety of possible inputs into scaffolding. For this tutorial we're going to scaffold from an existing database table that comes with MyEclipse Derby database. Choose the Database Schema option on the Select Artifact Type(s) panel. Click the Next button.
The next step is to select the DB connection for accessing the MyEclipse Derby database. This panel will show you all configured DB connections in the MyEclipse workspace, and you must select the MyEclipse Derby connection, which is a preconfigured DB connection in MyEclipse. Click the Next button.
The next step is to select the desired schema and database table(s) that should be used for scaffolding. When the CLASSICCARS schema is selected the tables list will be populated with a list of all the available tables. Add the EMPLOYEE and OFFICE table to the scaffolding list. Click the Next button.
The next panel will prompt you to select parent objects, and this panel also lets you override the derived name of the Java Object that will be created from the database table. Select the Customer Java object for parent. Click the Next button.
The next step is to specify which layers of the application should be scaffolded and which package names should be used for each layer. All the layers are enabled by default. Enter org.customerapp as the base package. The package names for the different layers will be automatically derived from the base package. A sub-package (i.e. web, service, DAO, and domain) will be added to the end of the base package. Click the Next button.
The next step is to specify which web clients should be generated for the web layer. As you can see, there are a variety of different web clients available, including Spring MVC, Spring Web Flow, Adobe Flex, GWT, JSF 2.0, and iPhone.
This tutorial is focused on Spring Flex, so click on the Generate checkbox for Adobe Flex. Click the Next button.
The next step is to configure some additional Flex Options. By default, the Flex SDK Home is populated with the packaged Open Source Flex 4.0 SDK located in the user directory. This path is configurable through Windows > Preferences > MyEclipse > Spring Code Generation > Flex.
If the Flex Builder plug-ins are installed into MyEclipse for Spring and the project contains the Flex nature, this Flex SDK Home text box will not show.
The next option is to specify the Flex MXML option, Flex 4.0 being the default. Either choice will be compiled against the Flex 4.0 SDK, unless you want to use a different Flex SDK or the Flex builder plugins.
For this tutorial keep the defaults, and click Next.
The next step is in an optional step to customize the UI. For this tutorial keep the defaults, and click Next.
The next step is to specify where the application (source code, configuration files, JSP, etc...) should be generated to in the current project and a few additional scaffolding options. For this panel the defaults are fine. Click the Next button.
The final configuration step is to specify the libraries that should be added to the current project, how they should be added (classpath containers or copied into project), and the version of Spring to use. For this panel the defaults are fine. Click the Next button.
NOTE: if using Spring 2.5, you'll need to consider a classpath dependency conflict described in this forum thread: http://www.myeclipseide.com/PNphpBB2-viewtopic-t-25763.html.
The final panel will give you a summary of everything that will be generated for you. Click the Finish button to scaffold the application from the information you provided in the wizard.
The current BlazeDS implementation has limited Lazy Loading support, so some considerations need to be mentioned when dealing with relationships. For more information and discussion about this topic and alternate options, see the myeclipseide.com Spring General forum post on Flex Scaffolding Hibernate Lazy Loading.
One-to-One or Many-to-One relationships: To get the Employee > Office (Many-to-One) child form to populate, the FetchType annotation needs to be updated to EAGER in the EmployeesApp\generated\org\employeesapp\domain\Employee.java file. Open that file, and find the @ManyToOne annotation. Change the FetchType enumeration as follows:
@ManyToOne(fetch = FetchType.EAGER) @JoinColumns(@JoinColumn(name = "OFFICECODE", referencedColumnName = "OFFICECODE")) @XmlTransient Office office;
One-to-Many or Many-to-Many relationships: Interestingly enough, no changes need to be made to these types of relationships to get the relationship results to populate. However, it needs to be noted that all the relationship data for to-Many type relationships will be pre-loaded automatically when the application first loads. If this becomes an issue with performance, take a look at the alternate options in the forum linked above.
The next step is to see the application in operation by deploying it to Tomcat. The running application can be used for validating the generated Adobe Flex components and observing the integration with the other components of the application
To deploy the application, right-click on the EmployeesApp project and select Run As --> MyEclipse Server Application.
MyEclipse Tomcat will start up. The first page will be a dashboard for accessing all scaffolded web clients. Since this tutorial only scaffolded a single parent object for Flex, the only option under Adobe Flex is View Employees. Click the button to see generated Spring Flex application in operation.
The Spring Flex application can be used to perform create, read, update, and delete functions on Employees and Offices. The following screen shots show some of the views.
The scaffolded application is compromised of many integrated software components, and the following diagrams provide an overview of which software components were generated and where they can be found in the project. Understanding what gets generated (and where) will help you find the individual or set of software components that you want use in your own developent projects.
The Adobe Flex scaffolding blueprint
provides a snapshot of what gets generated during scaffolding. The Adobe
Flex blueprint and the blueprints for the other ME4S code generations
capabilities are covered in more detail in the MyEclipse for Spring
reference guide. (see Additional Developer
Resources).
The following steps provide a general guideline on what to do if the Flex UI needs to be updated:
Make modifications to the *.mxml or *.as files.
Right-click the /build/Employeebuild.xml file and select Run As... Ant Build.
Check the console for a successful build or any errors.
NOTE: If any changes are made to the flex configuration files in WEB-INF, like the services-config.xml, the Flex Ant script needs to be run. Those configuration files are compiled in to the Flash file.
Now that you have a running Spring Flex application, you may want re-run the tutorial and scaffold different web clients, including Spring MVC, Web Flow, GWT, and iPhone.
You may also want to try the Spring Annotator and JAX-WS Annotator tutorials which are available in the Eclipse help system and online (see Additional Developer Resources).
What was your experience with this tutorial? Share your experience with us by completing a very brief survey.
Thank you for you interest in MyEclipse for Spring. If you are interested in learning more, the following developer resources are available:
Reference - Eclipse Help (MyEclipse for Spring 10.0 --> MyEclipse for Spring Reference) or Education Materials (online)
Tutorials - Eclipse Help (MyEclipse for Spring 10.0 --> Tutorials) or Education Materials (online)
Screencasts - MyEclipse for Spring YouTube Channel (online)
Support Forums - MyEclipse for Spring Forums (online)
Blog - MyEclipse for Spring Posts (online)