Skyway 6.3 Jump Start: CRUD App Scaffolding

Build a CRUD app in minutes with related domain objects

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

1. Prerequisites
2. Create the Project and Model Package
3. Create and Relate the Domain Objects
4. CRUD Scaffolding
5. Deploy the App
6. What's Next?
7. Appendix

1. Prerequisites

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.

2. Create the Project and Model Package

  1. Create a new Skyway Project by clicking the New Project icon in the Skyway toolbar. Name it SkywayHotels. Click Finish.

    Figure 1. Create a Skyway Project Wizard: SkywayHotels

    Create a Skyway Project Wizard: SkywayHotels

    Notice two new projects have been created: SkywayHotels, the modeling project; and SkywayHotels-Web, the standard Java Web Dynamic Project.

  2. Expand the Skyway Hotels modeling project, and right-click the Spring DSL artifact. Select New > Model Package. Name it com.skywayhotels.domain. Click Finish.

Figure 2. Create a Model Package: com.skywayhotels.domain

Create a Model Package: com.skywayhotels.domain

3. Create and Relate the Domain Objects

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.

  1. Right-click the com.skywayhotels.domain Model Package. Select New > Domain Object. Name it PreferredGuest.

  2. 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 NameTypePrimary Key
    usernameTextYes
    bedsInteger 
    creditCardExpiryMonthInteger 
    creditCardExpiryYearInteger 
    creditCardText 
    creditCardNameText 
    smokingBoolean 

    Figure 3. PreferredGuest Domain Object Fields

    PreferredGuest Domain Object Fields

  3. Right-click the com.skywayhotels.domain Model Package again. Select New > Domain Object. Name it Reservation.

  4. 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 NameTypePrimary Key
    rIdTextYes
    checkinDate 
    checkoutDate 

    Figure 4. Reservation Domain Object fields

    Reservation Domain Object fields

  5. Back in the PreferredGuest Domain Object Overview tab, click the Add... button in the Relationships section. Choose Reservation. Click OK.

  6. Name the relationship reservations, and set the Cardinality (1/n) to Many. Save.

  7. In the Reservation Domain Object, add the PreferredGuest relationship. Keep the name as preferredguest, and choose the reservations Inverse Name.

  8. Save the Reservation Domain Object, and then Save All.

Figure 5. Domain Object relationships

Domain Object relationships

4. CRUD Scaffolding

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.

  1. Right-click the PreferredGuest Domain Object. Choose Scaffolding > Generate CRUD.

    Figure 6. Scaffolding option

    Scaffolding option

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

    Figure 7. ReservationDAO Data Access Object connection

    ReservationDAO Data Access Object connection

    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.

5. Deploy the App

  1. 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)

  2. The following page should be shown:

    Figure 8. Preferred Guest index page

    Preferred Guest index page

    Feel free to create new Preferred Guests and Reservations. Here are some sample screenshots:

    Figure 9. New Reservation form page with Dojo calendar

    New Reservation form page with Dojo calendar

    Figure 10. Preferred Guest Reservations page (Master-Detail)

    Preferred Guest Reservations page (Master-Detail)

    Figure 11. SpringJavascript (Dojo) validation

    SpringJavascript (Dojo) validation

6. What's Next?

7. Appendix

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:

  1. Create a new Model Package under the Spring DSL named com.skywayhotels.dao.

  2. In com.skywayhotels.dao, create a new Skyway Data Access Object named HotelsDAO.

  3. In the Database Configuration tab, set the Connection to bookingDatabase.

  4. Click the Import Types link and choose the tables created by the above scripts.

  5. Save All.

  6. Continue with the section: CRUD Scaffolding.