Copyright © 2009 Skyway Software
Abstract
This simple tutorial details the steps required to create a fully functional SpringSource certified Java web application using Skyway Builder 6.3.
By using Skyway's visual DSL and scaffolding capabilities, a ready to run Eclipse Spring Java Dynamic Web project will be generated within a matter of minutes that include:
Related Domain Objects,
A DAO to manage the Domain Objects,
Finder methods in the DAO based on each domain object’s field,
A Service with CRUD operations for both Domain Objects,
A Controller with CRUD operations for both Domain Objects,
All the necessary Spring annotations and config files for a Spring MVC app,
All necessary CRUD JSP pages, including master-detail pages,
A Sitemesh enabled web application,
Web controls containing Spring Javascript validation (Dojo),
More CSS and javascript available for use and customization,
JUnits for every Service and Controllers,
SpringSource certified code and configuration files,
Generated code that follows Spring Recipes,
Generated code that looks like you would code it,
A modeling project that you can continue to use to enhance and generate more functionality in the web application, and
An Eclipse Dynamic Web Java Project which is separated from the Modeling project so experienced developers can hand code the rest of the application if they don't want to stay in the visual Spring DSL.
Table of Contents
The prerequisites needed to complete this quick start tutorial are:
Skyway 6.3 or later,
A sandbox environment with a server and database ( Skyway Builder Sandbox Setup Guide video), and
In the Data Source Explorer view create a new Data Connection to either MySQL or PostgreSQL and name it bookingDatabase.
Create a new Skyway Project by clicking the New Project icon in the Skyway toolbar. Name it SkywayHotels. Click Finish.
Notice two new projects have been created: SkywayHotels, the modeling project; and SkywayHotels-Web, the standard Java Web Dynamic Project.
Expand the Skyway Hotels modeling project, and right-click the Spring DSL artifact. Select New > Model Package. Name it com.skywayhotels.domain. Click Finish.
Note: These domain objects can be also be imported from a database by creating a Skyway Data Access Object and using the Import Tables link in the Database Configuration tab. See the Appendix for MySQL scripts and details.
Right-click the com.skywayhotels.domain Model Package. Select New > Domain Object. Name it PreferredGuest.
Add the following fields to the PreferredGuest Domain Object, and Save it when completed. See the figure below the table as a reference.
Table 1. PreferredGuest Domain Object fields
| Display Name | Type | Primary Key |
|---|---|---|
| username | Text | Yes |
| beds | Integer | |
| creditCardExpiryMonth | Integer | |
| creditCardExpiryYear | Integer | |
| creditCard | Text | |
| creditCardName | Text | |
| smoking | Boolean |
Right-click the com.skywayhotels.domain Model Package again. Select New > Domain Object. Name it Reservation.
Add the following fields to the Reservation Domain Object, and Save it when completed. See the figure below the table as a reference.
Table 2. Reservation Domain Object fields
| Display Name | Type | Primary Key |
|---|---|---|
| rId | Text | Yes |
| checkin | Date | |
| checkout | Date |
Back in the PreferredGuest Domain Object Overview tab, click the Add... button in the Relationships section. Choose Reservation. Click OK.
Name the relationship reservations, and set the Cardinality (1/n) to Many. Save.
In the Reservation Domain Object, add the PreferredGuest relationship. Keep the name as preferredguest, and choose the reservations Inverse Name.
Save the Reservation Domain Object, and then Save All.
It's now time to automatically generate all the necessary Java Spring code and configuration files to support the create, read, update, and delete functions for the Preferred Guest Domain Object and it's related Reservation Domain Object.
Right-click the PreferredGuest Domain Object. Choose Scaffolding > Generate CRUD.
When scaffolding completes, the last step is to configure the database connection in the DAOs. Double-click the PreferredGuestDAO, and go to the Database Configuration tab. Select the bookingDatabase connection created in the prerequisites section. Save the DAO. Do the same to the ReservationDAO.
Note: After creating a database connection, the default connection can be set for each new data store created by setting the connection in Window > Preferences > Skyway > Deployment.
The SkywayHotels-Web is ready to run. In the SkywayHotels-Web project, navigate to WebContent/pages/preferredguest. Right-click on index.jsp and select Run As... > Run on Server. Choose the Tomcat sandbox server. Click Ok. (Or copy and paste the following in your favorite browser: http://localhost:8080/SkywayHotels-Web/indexPreferredGuest.html)
The following page should be shown:
Feel free to create new Preferred Guests and Reservations. Here are some sample screenshots:
Review the generated Java Spring MVC SkywayHotels-Web project
Join the Skyway Community
Download more Sample Projects
MySQL preferredguest and reservation scripts (assuming skyway schema):
DROP TABLE IF EXISTS `skyway`.`preferredguest`; CREATE TABLE `skyway`.`preferredguest` ( `username` varchar(255) NOT NULL, `beds` int(11) default NULL, `creditCard` varchar(255) default NULL, `creditCardExpiryMonth` int(11) default NULL, `creditCardExpiryYear` int(11) default NULL, `creditCardName` varchar(255) default NULL, `smoking` bit(1) default NULL, PRIMARY KEY (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `skyway`.`reservation`; CREATE TABLE `skyway`.`reservation` ( `rId` varchar(255) NOT NULL, `checkin` date default NULL, `checkout` date default NULL, `preferredguest_username` varchar(255) default NULL, PRIMARY KEY (`rId`), KEY `FK63EEBAC426F2BCB` (`preferredguest_username`), CONSTRAINT `FK63EEBAC426F2BCB` FOREIGN KEY (`preferredguest_username`) REFERENCES `preferredguest` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
If using these scripts, perform the following steps in place of Section 3:
Create a new Model Package under the Spring DSL named com.skywayhotels.dao.
In com.skywayhotels.dao, create a new Skyway Data Access Object named HotelsDAO.
In the Database Configuration tab, set the Connection to bookingDatabase.
Click the Import Types link and choose the tables created by the above scripts.
Save All.
Continue with the section: CRUD Scaffolding.