+ All Categories
Home > Documents > Skyway Builder 6.3 - Spring MVC Tutorial

Skyway Builder 6.3 - Spring MVC Tutorial

Date post: 12-Sep-2021
Category:
Upload: others
View: 6 times
Download: 0 times
Share this document with a friend
70
Skyway Builder 6.3 - Spring MVC Tutorial 6.3.0.0 - 07/21/2009 Skyway Software
Transcript
Page 1: Skyway Builder 6.3 - Spring MVC Tutorial

Skyway Builder 6.3 - Spring MVC Tutorial

6.3.0.0 - 07/21/2009

Skyway Software

Page 2: Skyway Builder 6.3 - Spring MVC Tutorial

Skyway Builder 6.3 - Spring MVC Tutorial: 6.3.0.0 - 07/21/2009Skyway Software

PublishedCopyright © 2009 Skyway Software

Abstract

This document is a step-by-step guide for developing a Spring MVC application using Skyway Builder. The most recentversion of all Skyway Builder tutorials can always be found at www.skywayperspectives.org2.

2 http://www.skywayperspectives.org

Page 3: Skyway Builder 6.3 - Spring MVC Tutorial
Page 4: Skyway Builder 6.3 - Spring MVC Tutorial

iv

Table of Contents1. Introduction ................................................................................................................... 1

1. What's Covered ...................................................................................................... 12. Suggested Audience ................................................................................................. 13. Prerequisite Software ............................................................................................... 14. What are we going to build? ..................................................................................... 1

4.1. User Story ................................................................................................... 15. Support ................................................................................................................. 26. Spring DSL Artifacts ................................................................................................. 27. Application Layers ................................................................................................... 48. Implementation Overview ......................................................................................... 49. Development Process ............................................................................................... 6

9.1. Development Steps ....................................................................................... 62. Skyway Project ............................................................................................................... 8

1. TASK: Create Skyway Project for PAM ......................................................................... 83. Data Layer .................................................................................................................... 11

1. Model .................................................................................................................. 111.1. TASK: Add org.pam.tutorial.domain Model Package .......................................... 111.2. TASK: Add Appraisal Domain Object ............................................................... 12

2. Persistence ........................................................................................................... 142.1. TASK: Add org.pam.tutorial.dao Model Package ............................................... 142.2. TASK: Add AppraisalDAO Data Access Object ................................................... 15

3. Named Queries ..................................................................................................... 183.1. TASK: Add FindAllAppraisals Named Query to Data Access Object ........................ 18

4. Service Layer ................................................................................................................ 211. Model .................................................................................................................. 21

1.1. TASK: Add org.pam.tutorial.service Model Package ........................................... 211.2. TASK: Add AppraisalService to Project ............................................................ 221.3. TASK: Add SaveAppraisal Operation ............................................................... 231.4. TASK: Define Operation Input/Output Variables ............................................... 251.5. TASK: Create Save Action .............................................................................. 27

5. Web Layer .................................................................................................................... 301. Controller ............................................................................................................. 30

1.1. TASK: Add org.pam.tutorial.web Model Package ............................................... 301.2. TASK: Add AppraisalEntryController Web Controller .......................................... 311.3. TASK: Add Controller Variables ...................................................................... 311.4. TASK: Add the LoadAppraisals Operation ......................................................... 321.5. TASK: Add the InitNewAppraisal Operation ...................................................... 381.6. TASK: Add the ValidateAppraisal Operation ..................................................... 411.7. TASK: Add the SaveConfirmedAppraisal Operation ............................................ 47

2. View - JSP Pages .................................................................................................... 502.1. TASK: Create index.jsp Page .......................................................................... 502.2. TASK: Implement edit.jsp Page ...................................................................... 532.3. TASK: Implement confirm.jsp Page ................................................................. 562.4. TASK: Configure URL Mappings ...................................................................... 57

6. Deployment .................................................................................................................. 611. Configure Database ................................................................................................ 61

1.1. Add Data Source ......................................................................................... 611.2. Configure Data Access Object in Project .......................................................... 61

2. Configure Server .................................................................................................... 612.1. Add Server ................................................................................................. 612.2. Add PAM Project to Server ........................................................................... 61

Page 5: Skyway Builder 6.3 - Spring MVC Tutorial

Skyway Builder 6.3 -Spring MVC Tutorial

v

3. Run Application ..................................................................................................... 613.1. Start Server ................................................................................................ 613.2. Run Application .......................................................................................... 61

Page 6: Skyway Builder 6.3 - Spring MVC Tutorial

vi

List of Figures1.1. Project Meta-Data Model ............................................................................................... 21.2. End-User View of Application .......................................................................................... 41.3. Developer View of Application ........................................................................................ 52.1. Skyway Builder - Create Skyway Project ............................................................................ 82.2. PAM - Create a Skyway Project Wizard: Skyway Project ........................................................ 92.3. PAM - Create a Skyway Project Wizard: Folder Names ......................................................... 92.4. PAM - Create a Skyway Project Wizard: Artifact Category Mappings ...................................... 103.1. Skyway Builder - Create New Model Package ................................................................... 113.2. org.pam.tutorial.domain - New Model Package Wizard: Model Package ................................. 123.3. Skyway Builder - Create New Domain Object ................................................................... 123.4. Appraisal - New Domain Object Wizard: New Data Object .................................................. 133.5. Appraisal - Domain Object Editor: Overview ..................................................................... 133.6. Appraisal - Domain Object: Appraisal Fields ..................................................................... 143.7. org.pam.tutorial.dao - New Model Package Wizard: Model Package ...................................... 153.8. AppraisalDAO - New Data Access Object Wizard: New Data Store ......................................... 163.9. AppraisalDAO - New Data Access Object Wizard: Select Domain Object ................................. 163.10. AppraisalDAO - New Data Access Object Wizard: Add Domain Objects ................................. 173.11. AppraisalDAO - Data Access Object Editor: Overview ........................................................ 173.12. AppraisalDAO - Data Access Object Editor: Database Configuration ..................................... 183.13. FindAllAppraisals - New Named Query Wizard: New Named Query ..................................... 193.14. FindAllAppraisals - Named Query Editor: Overview .......................................................... 193.15. FindAllAppraisals - Named Query Editor: Inputs/Outputs .................................................. 203.16. FindAllAppraisals - Named Query Editor: Query Text ........................................................ 204.1. org.pam.tutorial.service - New Model Package Wizard: Model Package ................................. 224.2. Skyway Builder - New Service ........................................................................................ 224.3. AppraisalService - New Skyway Service Wizard: New Service ............................................... 234.4. SaveAppraisal - New Operation Wizard: New Skyway Operation ........................................... 244.5. SaveAppraisal - New Operation Wizard: Operation Options ................................................. 244.6. SaveAppraisal - Operation Editor: Overview ..................................................................... 254.7. Select Type ................................................................................................................ 264.8. SaveAppraisal - Operation Editor: Inputs/Outputs ............................................................. 264.9. Open Action Editor ...................................................................................................... 274.10. Step Palette .............................................................................................................. 284.11. SaveAppraisal (Save Action) - Action Editor .................................................................... 294.12. Properties: Modify Data Access Object Step - Modify ....................................................... 295.1. org.pam.tutorial.web - New Model Package Wizard: Model Package ..................................... 305.2. AppraisalEntryController - New Web Controller Wizard: New Web Controller ......................... 315.3. AppraisalEntryController - Controller Editor: Variables ........................................................ 325.4. Developer View of Application - LoadAppraisals ................................................................ 325.5. LoadAppraisals - New Operation Wizard: New Skyway Operation ......................................... 335.6. LoadAppraisals - New Operation Wizard: Operation Options ............................................... 345.7. LoadAppraisals - Operation Editor: Variables .................................................................... 355.8. LoadAppraisals - Operation Editor: Inputs/Outputs ............................................................ 365.9. Properties: Execute Named Query - Named Query ............................................................ 375.10. Properties: Execute Named Query - Outputs .................................................................. 375.11. Developer View of Application - InitNewAppraisal ........................................................... 385.12. InitNewAppraisal - New Operation Wizard: New Skyway Operation ..................................... 385.13. InitNewAppraisal - New Operation Wizard: Operation Options ........................................... 395.14. InitNewAppraisal - Operation Editor: Input/Output .......................................................... 405.15. Properties: Variable Assignment - Variable Assignment ..................................................... 415.16. Developer View of Application - ValidateAppraisal ........................................................... 41

Page 7: Skyway Builder 6.3 - Spring MVC Tutorial

Skyway Builder 6.3 -Spring MVC Tutorial

vii

5.17. ValidateAppraisal - New Operation Wizard: New Skyway Operation .................................... 425.18. ValidateAppraisal - New Operation Wizard: Operation Options ........................................... 435.19. ValidateAppraisal - Operation Editor: Variables ............................................................... 445.20. ValidateAppraisal - Operation Editor: Input/Output .......................................................... 445.21. Properties: Decision Step - Decision Criteria ................................................................... 465.22. Properties: Invoke Java (Confirm) - Java ......................................................................... 465.23. Properties: Invoke Java (Exit) - Java ............................................................................... 465.24. Developer View of Application - SaveConfirmedAppraisal .................................................. 475.25. SaveConfirmedAppraisal - New Operation Wizard: New Skyway Operation ........................... 485.26. SaveConfirmedAppraisal - New Operation Wizard: Operation Options ................................. 495.27. index.jsp - runtime view ............................................................................................. 515.28. index.jsp - New JavaServer Page Wizard: JavaServer Page ................................................. 515.29. index.jsp - New JavaServer Page Wizard: Select JSP Template ............................................. 525.30. index.jsp - full listing .................................................................................................. 535.31. edit.jsp - runtime view ............................................................................................... 545.32. edit.jsp - full listing .................................................................................................... 555.33. confirm.jsp - runtime view .......................................................................................... 565.34. confirm.jsp - full listing ............................................................................................... 575.35. URL Mapping ............................................................................................................ 585.36. AppraisalEntryController - Web Controller Editor: URL Mapping ......................................... 60

Page 8: Skyway Builder 6.3 - Spring MVC Tutorial

viii

List of Tables2.1. Project Wizard Configuration .......................................................................................... 93.1. Domain Object: Appraisal Fields .................................................................................... 133.2. Named Query Outputs: FindAllAppraisals ........................................................................ 193.3. Named Query Text: FindAllAppraisals .............................................................................. 204.1. Operation Wizard Configuration: SaveAppraisal ................................................................ 234.2. Operation Inputs: SaveAppraisal .................................................................................... 264.3. Action Implementation: SaveAppraisal.DefaultAction ......................................................... 285.1. Controller Variables: AppraisalEntryController .................................................................. 325.2. Operation Variables: LoadAppraisals ............................................................................... 345.3. Operation Outputs: LoadAppraisals ................................................................................ 355.4. Action Implementation: LoadAppraisals ........................................................................... 375.5. Operation Outputs: InitNewAppraisal .............................................................................. 395.6. Action Implementation: Default Action (InitNewAppraisalAppraisal) ..................................... 405.7. Operation Variables: LoadAppraisals ............................................................................... 435.8. Operation Inputs: ValidateAppraisal ................................................................................ 445.9. Action Implementation: ValidateAppraisal Action .............................................................. 455.10. Action Implementation: SaveConfirmedAppraisal Action ................................................... 505.11. AppraisalEntryController: URL Mappings ........................................................................ 59

Page 9: Skyway Builder 6.3 - Spring MVC Tutorial

1

Chapter 1. Introduction

1. What's CoveredWelcome to the Skyway Builder 6.3 - Spring MVC Tutorial, a step-by-step guide on how to develop aSpring MVC application from scratch using Skyway Builder. If you are instead interested in developinga Spring Web Flow application, please check out the Skyway Builder 6.3 - Spring Flow Tutorial. Bothtutorials build the exact same application, but each one leverages a different Spring Framework (WebFlow or MVC) and different set of code generation capabilities from Skyway Builder.

The Spring MVC tutorial will re-use portions of the Spring Web Flow tutorial, specifically the data andservice layers. Therefore Chapters 2 thru 4 of both tutorials are identical. If you've already completedthe Spring Web Flow tutorial, you can re-use that project for this tutorial and skip directly to Chapter 5(Web Layer).

2. Suggested AudienceThis tutorial is intended for developers with familiarity with Java-based web development and Eclipse. Itis assumed that the developer has basic experience with running a JEE Application Server and a databasemanagement system.

3. Prerequisite SoftwareThe prerequisites for completing this tutorial are:

• Skyway Builder 6.3 Community Edition or Enterprise Edition

• Java Application Server: Apache Tomcat 6.0

• Database Management System (DBMS): Postgres 8.1 -or- MySQL 5.1 Database

The setup of the application server and database management system is beyond the scope of this tutorial.If you need assistance setting up a sandbox which includes Tomcat and MySQL, please see refer to theSkyway Builder Sandbox Setup guide or Video Tutorial that can found in the Resources section of theSkyway Community Portal1.

4. What are we going to build?The goal of this tutorial is to provide a step-by-step example of building a Spring MVC application usingSkyway Builder. Skyway Builder CE is a subset of the development functionality, and this tutorial isn'tmaking use of any of the additional Skyway Builder EE features. So this tutorial is applicable to all versionsof Skyway Builder (CE and EE). While it is intentionally limited in scope, it introduces new users toapplication development using Skyway Builder.

The web application that will be implemented is a tool for managing the performance reviews of teammembers, and the application is called Performance Appraisal Management (PAM).

4.1. User StoryHere's a description of the requirements of PAM using user stories:

1 http://www.skywayperspectives.org

Page 10: Skyway Builder 6.3 - Spring MVC Tutorial

Introduction

2

User Stories

• Reviewer can list all performance appraisals.

• Reviewer can add a performance appraisal.

• An appraisal has employee first name, last name, and employee number.

• An appraisal covers three topics: design, programming, testing.

• An optional comment can be included for each appraisal.

• There are three appraisal ratings: 3-does not meet expectations, 2-meets expectations, 1-exceedsexpectations.

5. SupportIf you need help, there is a forum on the Skyway Community portal dedicated to the Skyway Tutorials2.

6. Spring DSL ArtifactsApplication development using Skyway Builder is accomplished by using (assembling and configuring)Spring DSL artifacts:

Figure 1.1. Project Meta-Data Model

Within Skyway Builder, there are graphical (and abstract) representations of application components.These components have direct correlations to Java, Spring, JPA, and JEE artifacts.

2 http://www.skywayperspectives.org/portal/web/guest/174/message_boards/category/10960

Page 11: Skyway Builder 6.3 - Spring MVC Tutorial

Introduction

3

Summary of Spring DSL Artifacts

• Projects are the top level artifact within the developer's workspace. All other Spring DSL artifacts mustbe made within a Skyway modeling project.

• A Model Package is a Spring DSL artifact for namespacing and grouping related Spring DSL components.A model package can contain any top-level Spring DSL elements, including other model packages.Model packages correlate directly to java packages (and UML packages), and Spring DSL artifactscreated in a model package will be generated into a matching Java package.

• A Domain Object is a Spring DSL artifact that defines the domain model of the application. By defaulta domain object is generated into a plain old java object (POJO). If a domain object is associated witha data access object, then the domain object is annotated as an @Entity (JPA) annotated class, andit's associated with a primary key class (@IdClass). Fields can be added to domain objects by using thebasic data types, and a domain object can have relationships to other domain objects.

• A Data Access Object (DAO) is a Spring DSL artifact used to separate data access logic from applicationlogic. A DAO manages the persistence of domain objects, and it is generated into @Repositoryannotated Spring components, a specialized stereotype for data access layer components. A DAO canalso contain predefined queries called Named Queries.

• A Named Query is a Spring DSL artifact creating predefined queries for the data access objects (DAOs).Named queries are defined using either SQL or JPQL (Java Persistence Query Language), and NamedQueries are generated into @NamedQueries and @NamedQuery annotations in Spring @Repositorycomponents.

• A Service is a Spring DSL artifact that defines a service layer component, and it gets generated intoa @Service annotated Spring component, a specialized stereotype for service layer components. AService contains a set of Operations which are generated into Service methods.

• A Web Controller is a Spring DSL artifact that defines the web layer of an application using SpringMVC. Web Controllers get generated into a @Controller annotated Spring component, a specializedstereotype for web layer components. A Web Controller contains a set of Operations which aregenerated into methods for handling web requests.

• An Operation is a Spring DSL artifact that defines methods for both Services and Controllers. Operationsrepresent application logic, and they use inputs and outputs for exchanging data. Operations aregenerated directly in the respective Service and Controller classes, and they are generated slightlydifferently to account for the different implementations needed for the Spring stereotypes.

• An Actions is a Spring DSL artifact for implementing operations using model-driven development.They are used to implement service and controller operations in Java using drag-n-drop steps that aresequenced together into functionality.

• A Component is a Spring DSL artifact that defines a generic container for data. A componentgets generated into an @Component annotated Spring component, a generic stereotype for Springmanaged components with configurable scope. Components are typically used as data transfer objects(DTO) and form backing objects.

• A Flow is used to implement the web layer of an application using Spring Web Flow.

• Java Server Pages (JSP) are used to implement the Presentation layer of an applicaiton. JSPs are usedfor both Spring MVC and Spring Web Flow applications.

• An Exception is a Spring DSL artifact that defines custom exceptions. Exceptions are generated intoexception classes in Java.

Page 12: Skyway Builder 6.3 - Spring MVC Tutorial

Introduction

4

7. Application LayersThis application will be implemented in three layers:

The web layer (also referred to as the UI layer) is primarily concerned with presenting the user interfaceand handling user interactions/events. The Skyway artifacts for implementing the web layer of a SpringMVC application are the Controller, Operation, Component, Action, Steps and JSP pages. The Skywayartifacts for implementing the web layer of a Spring Web Flow application are the Flows and JSP pages.(This tutorial is concerned with developing a Spring MVC application.)

The service layer (also referred to as the logic layer or business layer) represents the core functionalityof the application being built. The Skyway artifacts for implementing the service layer are the Service,Operation, Action, and Steps.

The data layer (also referred to as the persistence layer or domain object layer) is represented bya domain model; a distinct set of inter-related application objects that embody the functionality andcharacteristics of the system being built. This layer also encompasses the persistence of the domain modelto and from a database. The Skyway artifacts for implementing the data layer are the Domain Object,Data Access Object and Named Query artifacts.

8. Implementation OverviewFigure 1.2. End-User View of Application

End-User View of Application

• Step 1: End-user goes to index.html, the starting page of the application. From here the user willsee a list of performance appraisals in the database. There is also a New Appraisal hyperlink that theuser can click on to start the new appraisal process.

Page 13: Skyway Builder 6.3 - Spring MVC Tutorial

Introduction

5

• Step 2: Clicking on the New Appraisal hyperlink loads the edit page, the appraisal entry form. The end-user enters all the data, and clicks the Next button.

• Step 3: After clicking on the Next button, the appraisal will be validated on the server. If the appraisalpasses validation, the confirm page will load. If the appraisal doesn't pass validation, the edit page willbe reloaded.

• Step 4: From the confirm page, the end-user will confirm that the appraisal should be submitted toPAM system.

• Step 5: Upon a successful save, the user will be returned to the index page.

Figure 1.3. Developer View of Application

Developer View of Application using Skyway Builder

• Step 1: Prior to the page rendering, there is some data loading that needs to occur. This is implementedin the LoadAppraisals operation. The URL Mapping is configured to fire the LoadAppraisals operationprior to the /index.jsp page being rendered.

• Step 2: The "New Appraisal" hyperlink on the index.jsp page is configured with a URL that is mappedto call the InitNewAppraisal operation. This action will initialize variables, and upon completion willdefer to the /edit.jsp page to render the view (or response).

• Step 3: The end-user will press the "Next" button when finished filling in the appraisal form. The "Next"button is configured with a URL that is mapped to call the ValidateAppraisal operation. This operationwill verify that all the required appraisal details were specified by the end-user. This operation can goto one of two pages based on the result of the validation logic. This is accomplished with an operationvariable that is used to determine the view. If the appraisal passes validation, the operation will set theoperation variable to /confirm.jsp. If the appraisal doesn't pass validation, the operation will set theoperation variable to the /edit.jsp page.

• Step 4: The "Confirm" button on the confirm.jsp page is configured with a URL that is mapped to callthe SaveConfirmedAppraisal operation. This operation will call the SaveAppraisal service (which willpersist the appraisal).

• Step 5: Upon completion /index.jsp page will be reloaded.

Use the following Skyway Navigator screenshot as a guideline for implementing the project

Page 14: Skyway Builder 6.3 - Spring MVC Tutorial

Introduction

6

9. Development Process

9.1. Development Steps

Application development with Skyway Builder generally consists of five steps, and this tutorial isstructured according to these steps.

High-level Development Steps Defined

• Project - create a project

• Data Layer - define the data layer

Page 15: Skyway Builder 6.3 - Spring MVC Tutorial

Introduction

7

• Services Layer - define the service layer

• Web Layer - define the web layer

• Deploy - deploy the project

Page 16: Skyway Builder 6.3 - Spring MVC Tutorial

8

Chapter 2. Skyway Project

This chapter will outline the steps for creating the PAM project.

1. TASK: Create Skyway Project for PAMSkyway Projects are the top level development artifact within Skyway Builder. All other Skyway artifactsmust reside inside a Skyway Project. The target project is the project that contains the actual Springapplication, a standard Eclipse dynamic web project. The code generated from the Skyway artifacts isgenerated to the configured target project(s). In many cases (as is the case with PAM) a web applicationis implemented as a single web project, which contains any and all code and configuration needed toprovide its functionality..

Steps:

1. Right click in Skyway Navigator, and select New-->Project

2. From the New Project Wizard, pick "Skyway Project" from the "Skyway" folder. This will open theCreate Skyway Project Wizard, which is used to specify a name, location and sub-folders to be usedfor the project.

Figure 2.1. Skyway Builder - Create Skyway Project

3. Configure the Create Skyway Project Wizard as follows:

Page 17: Skyway Builder 6.3 - Spring MVC Tutorial

Skyway Project

9

Table 2.1. Project Wizard Configuration

Panel Field Value

Skyway Project Project Name: PAM

Skyway Project Use default location: yes (default)

Folder Names Folder to create for models: models (default)

Artifact Category Mappings Use Maven to create projectsfor generated code

no (default)

Figure 2.2. PAM - Create a Skyway Project Wizard: Skyway Project

Figure 2.3. PAM - Create a Skyway Project Wizard: Folder Names

Page 18: Skyway Builder 6.3 - Spring MVC Tutorial

Skyway Project

10

Figure 2.4. PAM - Create a Skyway Project Wizard: Artifact Category Mappings

4. When done, click Finish.

You should now have two Eclipse projects:

1. PAM - a modeling project for storing the Skyway models

2. PAM-Web - a dynamic web module project for storing and deploying the generated Spring application

Page 19: Skyway Builder 6.3 - Spring MVC Tutorial

11

Chapter 3. Data Layer

The data layer (also referred to as the persistence layer or domain object layer) is represented by a domainmodel; a distinct set of inter-related application objects that embody the functionality and characteristicsof the system being built. This layer also encompasses the persistence of the domain model to and froma database. The Spring DSL artifacts for implementing the data layer are the Domain Object and DataAccess Object artifacts.

This chapter will outline the steps for implementing the data layer for PAM.

1. Model

1.1. TASK: Add org.pam.tutorial.domain Model Package

Model Packages are used for grouping related development artifacts into namespaces. Model packagescorrelate directly to java packages. Spring DSL artifacts created in a model package will be generated intoa matching Java package.

Steps:

1. Right click on the Spring DSL node in the PAM project , and select New-->Model Package

Figure 3.1. Skyway Builder - Create New Model Package

2. From the New Model Package Wizard, enter "org.pam.tutorial.domain" as the package. This will bethe name of the new Model Package.

Page 20: Skyway Builder 6.3 - Spring MVC Tutorial

Data Layer

12

Figure 3.2. org.pam.tutorial.domain - New Model Package Wizard: Model Package

3. When done, click Finish.

1.2. TASK: Add Appraisal Domain Object

Domain Objects are used to define domain objects that will be utilized within an application. You canadd object attributes by using the basic Domain Objects, and you can also specify relationships to otherDomain Objects and their cardinality.

Steps:

1. Righ click on the org.pam.tutorial.domain model package , and select New-->Domain Object

Figure 3.3. Skyway Builder - Create New Domain Object

2. From the New Domain Object Wizard, enter "Appraisal" for the filename. This will be the name ofthe new Domain Object.

Page 21: Skyway Builder 6.3 - Spring MVC Tutorial

Data Layer

13

Figure 3.4. Appraisal - New Domain Object Wizard: New Data Object

3. When done, click Finish. This will open the Domain Object editor.

Figure 3.5. Appraisal - Domain Object Editor: Overview

4. From the Overview tab of the Domain Object editor, add the following fields.

Table 3.1. Domain Object: Appraisal Fields

Display Name Type Primary Key

employeeNo Text Yes

lastName Text

firstName Text

ratingDesign Integer

Page 22: Skyway Builder 6.3 - Spring MVC Tutorial

Data Layer

14

Display Name Type Primary Key

ratingProgramming Integer

ratingTesting Integer

comments LargeText

Figure 3.6. Appraisal - Domain Object: Appraisal Fields

5. Save the Domain Object using File-->Save. You may also close the editor.

2. Persistence

2.1. TASK: Add org.pam.tutorial.dao Model Package

Model Packages are used for grouping related development artifacts into namespaces. Model packagescorrelate directly to java packages. Spring DSL artifacts created in a model package will be generated intoa matching Java package.

Steps:

1. Righ click on the Spring DSL node in the PAM project , and select New-->Model Package

2. From the New Model Package Wizard, enter "org.pam.tutorial.dao" as the package. This will be thename of the new Model Package.

Page 23: Skyway Builder 6.3 - Spring MVC Tutorial

Data Layer

15

Figure 3.7. org.pam.tutorial.dao - New Model Package Wizard: Model Package

3. When done, click Finish.

2.2. TASK: Add AppraisalDAO Data Access Object

Data Access Objects are abstract representations of real databases (or persistence mechanisms), andthey manage persistence for a set of Domain Objects. When designing the models there is no need toknow the detail of the database (vendor, version, IP, etc.), but simply a need to know that one exists formodeling database activity. When models are deployed, the developer late binds each Data Store to areal, physical implementation of a database.

Steps:

1. Right click on the org.pam.tutorial.dao model package, and select New-->Data Access Object

2. From the New Data Access Object Wizard, enter "AppraisalDAO" for the filename. This will be thename of the new Data Access Object. Clicking Next to go to the next panel.

Page 24: Skyway Builder 6.3 - Spring MVC Tutorial

Data Layer

16

Figure 3.8. AppraisalDAO - New Data Access Object Wizard: New Data Store

3. From the Add Domain Object panel, click the Add button, and select the "Appraisal" domain objectfrom the Domain Objects list.

Figure 3.9. AppraisalDAO - New Data Access Object Wizard: Select Domain Object

Page 25: Skyway Builder 6.3 - Spring MVC Tutorial

Data Layer

17

Figure 3.10. AppraisalDAO - New Data Access Object Wizard: Add Domain Objects

4. When done, click Finish. This will open the Data Access Object editor.

Figure 3.11. AppraisalDAO - Data Access Object Editor: Overview

5. On the Database Configuration tab the database connection should be defaulted to the dataconnection you created when you performed the Sandbox setup prerequisites. Per the sandbox setupguide, the db connection is called SkywayDB. If you haven't created a connection yet, you can createa new connection from here.

Page 26: Skyway Builder 6.3 - Spring MVC Tutorial

Data Layer

18

Figure 3.12. AppraisalDAO - Data Access Object Editor: Database Configuration

6. Save the Data Access Object using File-->Save.

3. Named Queries

3.1. TASK: Add FindAllAppraisals Named Query to Data AccessObject

Named Queries are a mechanism for predefining queries for the Domain Objects associated with a DataAccess Object. Named queries are defined using either SQL or JPQL (Java Persistence Query Language).The benefits of named queries is that the queries are centralized and they can more easily be re-used.

Steps:

1. Right click on the AppraisalDAO, and select New-->Named Query

2. From the New Named Query Wizard, enter "FindAllAppraisals" for the name. This will be the nameof the new named query.

Page 27: Skyway Builder 6.3 - Spring MVC Tutorial

Data Layer

19

Figure 3.13. FindAllAppraisals - New Named Query Wizard: New Named Query

3. When done, click Finish. This will open the Named Query editor.

Figure 3.14. FindAllAppraisals - Named Query Editor: Overview

4. The signature of the named query is specified on the Inputs/Outputs tab. Add an output variable perthe following table. Adding input or output variables is very similar to adding variables to a project.As you add variables, the type picker will show you the Skyway Basic types plus the Domain Objectsof any open Skyway projects.

Table 3.2. Named Query Outputs: FindAllAppraisals

Name Type Collection

appraisals Appraisal Yes

Page 28: Skyway Builder 6.3 - Spring MVC Tutorial

Data Layer

20

Figure 3.15. FindAllAppraisals - Named Query Editor: Inputs/Outputs

5. The query is specified on the Query Text tab, and it defines the query in either SQL or JPQL. . Configurethe query according to the following table.

Table 3.3. Named Query Text: FindAllAppraisals

Field Value

Query Type JPQL

Query Text select allAppraisals from Appraisal allAppraisals

Figure 3.16. FindAllAppraisals - Named Query Editor: Query Text

6. Save the named query using File-->Save.

Page 29: Skyway Builder 6.3 - Spring MVC Tutorial

21

Chapter 4. Service Layer

The service layer (also referred to as the logic layer or business layer) represents the core functionalityof the application being built. The Spring DSL artifacts for implementing the service layer are the Service,Operation, Action, and Steps.

This chapter will outline the steps for implementing the service layer of PAM.

For the PAM project there is only one operation in the service layer. The SaveAppraisal operation isintended to handle all persistence logic associated with saving an appraisal. For the tutorial the logic isvery basic; the appraisal will simply be persisted to a database. However as the application requirementschange in the future, you can add additional functionality (i.e. checking for duplicate entries, sendingemail notifications, updating HR system).

1. Model

1.1. TASK: Add org.pam.tutorial.service Model Package

Model Packages are used for grouping related development artifacts into namespaces. Model packagescorrelate directly to java packages. Spring DSL artifacts created in a model package will be generated intoa matching Java package.

Steps:

1. Righ click on the Spring DSL node in the PAM project , and select New-->Model Package

2. From the New Model Package Wizard, enter "org.pam.tutorial.service" as the package. This will bethe name of the new Model Package.

Page 30: Skyway Builder 6.3 - Spring MVC Tutorial

Service Layer

22

Figure 4.1. org.pam.tutorial.service - New Model Package Wizard: Model Package

3. When done, click Finish.

1.2. TASK: Add AppraisalService to Project

A Skyway Service is a container for logic. Before defining an implementing the logice, the Service needsto be created.

Steps:

1. Right click on org.pam.tutorial.service model package, and select New-->Service

Figure 4.2. Skyway Builder - New Service

2. From the New Skyway Service Wizard, enter "AppraisalService" for the filename. This will be the nameof the new service. The container for this service should be the project (PAM). If the project is nothighlighted, then select the project.

Page 31: Skyway Builder 6.3 - Spring MVC Tutorial

Service Layer

23

Figure 4.3. AppraisalService - New Skyway Service Wizard: New Service

3. When done, click Finish.

1.3. TASK: Add SaveAppraisal Operation

Service functions are specified as Operations, which represent stateless application logic. In additionto a name and description, the operation definition consists of an operation interface and operationresources. The actual application logic of an operation is implemented using Actions (which will becovered in a later task).

In the case of PAM, the approval logic is implemented as a Service. It could have been implemented inthe web layer, but it would have (a) limited the reusability of the logic, and (b) not given you a chanceto implement a Service.

Steps:

1. Right click on the AppraisalService service, and select New-->Operation

2. Configure the Create Skyway Operation Wizard as follows:

Table 4.1. Operation Wizard Configuration: SaveAppraisal

Panel Field Value

New Skyway Operation File Name: SaveAppraisal

Entry Point Action Create an entry point action: yes (default)

Entry Point Action Action Name: DefaultAction

Page 32: Skyway Builder 6.3 - Spring MVC Tutorial

Service Layer

24

Figure 4.4. SaveAppraisal - New Operation Wizard: New Skyway Operation

Figure 4.5. SaveAppraisal - New Operation Wizard: Operation Options

3. When done, click Finish. This will open the Operation editor.

Page 33: Skyway Builder 6.3 - Spring MVC Tutorial

Service Layer

25

Figure 4.6. SaveAppraisal - Operation Editor: Overview

The operation name will be used when referencing this operation from elsewhere in the application.

Depending on the amount of functionality in an operation, an operation can be implemented with oneor more actions. In the event there's multiple actions, one of the actions must be defined as the entrypoint. When you initially create an operation, you can have the initial action automatically created foryou, and you can also have the action preconfigured as the entry point.

1.4. TASK: Define Operation Input/Output Variables

Inputs and Output variables partly define the operation contract. When another application artifactwants to call an operation, it must pass in the input variables and accept the output variables.

In the case of the SaveAppraisal operaton, the input will be an appraisal object, and there are no outputs.

Steps:

1. From the Inputs/Outputs tab of the Operation Editor, add an input variable per the following table.Adding input and output variables is very similar to adding variables to a project. As you add variables,the type picker will show you the Skyway Basic types plus the Domain Objects of any open Skywayprojects.

Page 34: Skyway Builder 6.3 - Spring MVC Tutorial

Service Layer

26

Figure 4.7. Select Type

Table 4.2. Operation Inputs: SaveAppraisal

Name Type Collection

inAppraisal Appraisal No

Figure 4.8. SaveAppraisal - Operation Editor: Inputs/Outputs

2. Save the operation using File-->Save.

Page 35: Skyway Builder 6.3 - Spring MVC Tutorial

Service Layer

27

1.5. TASK: Create Save Action

While the operation defines the interface and resources needed for an application function, thefunctionality is actually implemented using Actions. The developer defines the logic to be performed bysequencing steps together.

Adding actions to the an operation is normally accomplished by right-clicking on the Operation, andselectidng "New-->Action". However during the creation of the operation, we were given the optionto have an action automatically created and preconfigured as the entry point. If you expand theSaveAppraisal operation, you will see the "DefaultAction" action.

Steps:

1. Open the Save action by double-clicking on the action in the Project Explorer. This will open the Actioneditor.

Figure 4.9. Open Action Editor

2. From here you will model the implementation of the operation. In this case the operation will beimplemented with one step, so it can be modeled using only the entry-point action. However in othercases, as described earlier, you may choose to decompose the logic into multiple actions that arestrung together by the entry-point action.

To implement the Action, open the step palette.

Page 36: Skyway Builder 6.3 - Spring MVC Tutorial

Service Layer

28

Figure 4.10. Step Palette

3. Implementing the Action consists of dropping the desired steps onto the canvas, configuring the steps(properties), and stringing the steps together into a flow. Click on the Modify Data Access Object stepand then click on the canvas. Repeat this for all the steps listed in the following table.

4. Once the steps are added the canvas, you can configure the steps by double-clicking on the step toopen the step properties. Configure the step properties using the following table as a reference.

Table 4.3. Action Implementation: SaveAppraisal.DefaultAction

Step Name Step Type Configuration

Persist Appraisal

Modify DataAccess Object

Properties-->Modify Tab

• Data Access Object: AppraisalDAO

• Operation: Update

• Operation Input: inAppraisal

Stop

Stop

Note Optional Text: "This action persists the appraisalto the data source."

Page 37: Skyway Builder 6.3 - Spring MVC Tutorial

Service Layer

29

5. To connect the steps, click on the Connector in the palette, click on the first step (Persist Appraisal)and drag to the second step (Stop).

6. Save the action using File-->Save.

Figure 4.11. SaveAppraisal (Save Action) - Action Editor

Figure 4.12. Properties: Modify Data Access Object Step - Modify

Page 38: Skyway Builder 6.3 - Spring MVC Tutorial

30

Chapter 5. Web Layer

The web layer (also referred to as the UI layer) is primarily concerned with presenting the user interfaceand implementing the behavior of the application. The Spring DSL artifacts for implementing the weblayer are the Controllers, Operations, Components, Action, Steps, and JSP pages.

This chapter will outline the steps for implementing the web layer of PAM.

1. Controller

1.1. TASK: Add org.pam.tutorial.web Model PackageModel Packages are used for grouping related development artifacts into namespaces. Model packagescorrelate directly to java packages. Spring DSL artifacts created in a model package will be generated intoa matching Java package.

Steps:

1. Righ click on the Spring DSL node in the PAM project , and select New-->Model Package

2. From the New Model Package Wizard, enter "org.pam.tutorial.web" as the package. This will be thename of the new Model Package.

Figure 5.1. org.pam.tutorial.web - New Model Package Wizard: Model Package

Page 39: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

31

3. When done, click Finish.

1.2. TASK: Add AppraisalEntryController Web ControllerAs described earlier Web Controllers are used along with the JSP pages (located in the WebContent)to implement the Web layer of an application. The JSP pages represent the View in MVC, and WebControllers represent the Controller in MVC. A Web Controller can also have one or more Components,but Components aren't needed for the PAM project.

Steps:

1. Right click on org.pam.tutorial.web model package, and select New-->Web Controller

2. From the New Web Controller Wizard, enter "AppraisalEntryController" for the filename. This will bethe name of the new web controller. The container for this web controller should be the project (PAM).If the project is not highlighted, then select the project.

Figure 5.2. AppraisalEntryController - New Web Controller Wizard: New WebController

3. When done, click Finish.

1.3. TASK: Add Controller VariablesController variables are for specifying data that can be shared across multiple user interactions. Whendefining operations (covered in a later section) you can specify input data (data solicited from the end-user) and output data (data displayed to the end-user), and operation input/output data is inherentlyrequest-scoped. When defining controller variables, you are specifying data that will be maintained acrossmultiple requests.

Steps:

Page 40: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

32

1. From the AppraisalEntryController, switch to the Variables tab and add variables according to thefollowing table:

Table 5.1. Controller Variables: AppraisalEntryController

Name Type Collection On Request

appraisal Appraisal No Yes

2. Figure 5.3. AppraisalEntryController - Controller Editor: Variables

3. When done, click Finish.

1.4. TASK: Add the LoadAppraisals Operation

Operations in the context of a web application (as opposed to a service) implement the logic for handlinguser-generated events. The developer defines the operation signature, variables and implementation(using Skyway actions).

Figure 5.4. Developer View of Application - LoadAppraisals

The first operation, LoadAppraisals, is intended to load all the current appraisals into a variable(appraisals) that can be displayed to the end-user in a table. This operation is only concerned with loadingthe data, the presentation of the data will be covered in a later section.

Page 41: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

33

When this action is created, a partially configured URL Mapping will also be created. In a later section wewill complete the configuration of the URL Mapping to fire prior to displaying the index page.

Steps:

1. Right-click on AppraisalEntryController,, and select New-->Operation to open the New OperationWizard.

2. From the New Skyway Operation panel, enter "LoadAppraisals" for the name. This will be the name ofthe new operation. The container for this action should be the controller (AppraisalEntryController).If the controller is not highlighted, then select the controller. When done, click Next.

Figure 5.5. LoadAppraisals - New Operation Wizard: New Skyway Operation

3. From the Operation Options panel, you are prompted whether a URL mapping should be created forthis operation. A URL Mapping will configure the operation to be available as a web resource using thespecified URL. You are also prompted whether an entry point action should be created. An action isa model-based artifact for implementing the operation logic using Skyway's drag-n-drop steps, whichwill ultimately be generated to Java code in the operation method. For this tutorial accept the alldefaults on the Operation Options panel.

Page 42: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

34

Figure 5.6. LoadAppraisals - New Operation Wizard: Operation Options

4. When done, click Finish. This will open the Operation editor.

5. Operations variables are specified on the Variables tab. The LoadAppraisals operation requires onevariable for storing the list of appraisals that will be retrieved from the database. Add a variablesper the following table. Adding variables is very similar to adding variables to a project. As you addvariables, the type picker will show you the Skyway Basic types plus the Domain Objects of any openSkyway projects.

Table 5.2. Operation Variables: LoadAppraisals

Name Type Collection

appraisalList Appraisal Yes

Page 43: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

35

Figure 5.7. LoadAppraisals - Operation Editor: Variables

6. The signature of the operation is specified on the Inputs/Outputs tab. The LoadAppraisals operationrequire a single output variable for exposing the data to the View. Add an output variable per thefollowing table. Adding variables is very similar to adding variables to a project. As you add variables,the type picker will show you the Skyway Basic types plus the Domain Objects of any open Skywayprojects.

Table 5.3. Operation Outputs: LoadAppraisals

Name Type Collection Assignment

appraisals Appraisal Yes appraisalList (fromoperation variables)

Page 44: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

36

Figure 5.8. LoadAppraisals - Operation Editor: Inputs/Outputs

7. When done, save the operation. Next you will implement the DefaultAction that is contained withinthe Operation. Open the action by expanding the controller in the Project Explorer, and double-clickon DefaultAction.

8. From here you will model the implementation of the action. Implementing the Action consists ofdropping steps onto the canvas, configuring the steps, and stringing the steps together into a flow. Thefollowing diagram shows the implementation of the action.

9. For the LoadAppraisals operation there are only two steps. Once a step is added the canvas, you canconfigure the step by double-clicking on the step to open the step properties.

Page 45: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

37

Table 5.4. Action Implementation: LoadAppraisals

Step Name Step Type Configuration

Retrieve All Appraisals

Execute Named Query

Properties-->Named Query

• Named Query:PAM.AppraisalDAO.FindAllAppraisals

Properties-->Outputs

• appraisals (Output Variable) - appraisalList(Assignment)

Stop

Stop

Note Optional Text: "This action persists the appraisalto the data source."

Figure 5.9. Properties: Execute Named Query - Named Query

Figure 5.10. Properties: Execute Named Query - Outputs

10.A Note can be optionally added to an action to describe the functionality of the action.

Page 46: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

38

1.5. TASK: Add the InitNewAppraisal Operation

Figure 5.11. Developer View of Application - InitNewAppraisal

The InitNewAppraisal operation is intended to prepare the application for creating a new appraisal. Whenthe "New" hyperlink is clicked by the end-user, the InitNewAppraisal operation will be invoked, whichwill create a new appraisal object to make sure that any data that may have been previously entered bythe end-user is discarded.

Steps:

1. Right-click on AppraisalEntryController,, and select New-->Operation to open the New OperationWizard.

2. From the New Skyway Operation panel, enter "InitNewAppraisal" for the name. This will be the nameof the new operation. The container for this action should be the controller (AppraisalEntryController).If the controller is not highlighted, then select the controller. When done, click Next.

Figure 5.12. InitNewAppraisal - New Operation Wizard: New Skyway Operation

Page 47: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

39

3. From the Operation Options panel, you are prompted whether a URL mapping should be created forthis operation. A URL Mapping will configure the operation to be available as a web resource using thespecified URL. You are also prompted whether an entry point action should be created. An action isa model-based artifact for implementing the operation logic using Skyway's drag-n-drop steps, whichwill ultimately be generated to Java code in the operation method. For this tutorial accept the alldefaults on the Operation Options panel.

Figure 5.13. InitNewAppraisal - New Operation Wizard: Operation Options

4. When done, click Finish. This will open the Operation editor

5. The signature of the operation is specified on the Inputs/Outputs tab. Since the operation will bemodifying the appraisal variable, the appraisal variable must be specified as an output variable. Addan output variables per the following table. Adding variables is very similar to adding variables to aproject. As you add variables, the type picker will show you the Skyway Basic types plus the DomainObjects of any open Skyway projects.

Table 5.5. Operation Outputs: InitNewAppraisal

Name Type Collection Assignment

appraisal Appraisal No appraisal (fromcontroller variables)

Page 48: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

40

Figure 5.14. InitNewAppraisal - Operation Editor: Input/Output

6. Next you will implement the DefaultAction that is contained within the Operation. Open the actionby expanding the controller in the Project Explorer, and double-click on DefaultAction.

7. From here you will model the implementation of the action. Implementing the Action consists ofdropping steps onto the canvas, configuring the steps, and stringing the steps together into a flow. Thefollowing diagram shows the implementation of the InitNewAppraisal action.

8. In this case there are only two steps. Once a step is added the canvas, you can configure the step bydouble-clicking on the step to open the step properties.

Table 5.6. Action Implementation: Default Action (InitNewAppraisalAppraisal)

Step Name Step Type Step Properties

New Appraisal Properties-->Variable Assignment

Page 49: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

41

Step Name Step Type Step Properties

Variable Assignment

• Expression Language:Java

• Expression: appraisal = neworg.pam.tutorial.domain.Appraisal();

Stop

Stop

Note Optional Text: "This action persists the appraisalto the data source."

Figure 5.15. Properties: Variable Assignment - Variable Assignment

A Note can be optionally added to an action to describe the functionality of the action.

9. When done, save the action.

1.6. TASK: Add the ValidateAppraisal Operation

Figure 5.16. Developer View of Application - ValidateAppraisal

The ValidateAppraisal operation is responsible for validating the appraisal data that was entered by theend-user. In this implementation the validation logic is very basic. The only thing that is being verified isthat an employeeNo is specified. Based on the evaluation of the appraisal object, this action will directthe end-user either to the /confirm.jsp page or back to the /edit.jsp page. In contrast with the otheractions in PAM which go to one and only one page (determined by URL mapping), the next page for thisoperation will be specified in the implementation of the operation..

Steps:

Page 50: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

42

1. Right-click on AppraisalEntryController, and select New-->Operation to open the New OperationWizard.

2. From the New Skyway Operation panel, enter "ValidateAppraisal" for the name. This will be the nameof the new operation. The container for this action should be the controller (AppraisalEntryController).If the controller is not highlighted, then select the controller. When done, click Next.

Figure 5.17. ValidateAppraisal - New Operation Wizard: New Skyway Operation

3. From the Operation Options panel, you are prompted whether a URL mapping should be created forthis operation. A URL Mapping will configure the operation to be available as a web resource using thespecified URL. You are also prompted whether an entry point action should be created. An action isa model-based artifact for implementing the operation logic using Skyway's drag-n-drop steps, whichwill ultimately be generated to Java code in the operation method. For this tutorial accept the alldefaults on the Operation Options panel.

Page 51: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

43

Figure 5.18. ValidateAppraisal - New Operation Wizard: Operation Options

4. When done, click Finish. This will open the Operation editor.

5. Operations variables are specified on the Variables tab. The ValidateAppraisal operation requires onevariable (page) for dynamic page navigation, the variable will be used to control page flow. Add avariables per the following table. As you add variables, the type picker will show you the Skyway Basictypes plus the Domain Objects of any open Skyway projects.

Table 5.7. Operation Variables: LoadAppraisals

Name Type Collection

page Text No

Page 52: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

44

Figure 5.19. ValidateAppraisal - Operation Editor: Variables

6. The signature of the operation is specified on the Inputs/Outputs tab. Add input and output variablesper the following tables. Adding variables is very similar to adding variables to a project. As you addvariables, the type picker will show you the Skyway Basic types plus the Domain Objects of any openSkyway projects.

Table 5.8. Operation Inputs: ValidateAppraisal

Name Type Collection

appraisal Appraisal No

Figure 5.20. ValidateAppraisal - Operation Editor: Input/Output

7. When done, save the operation. Next you will implement the DefaultAction that is contained withinthe Operation. Open the action by expanding the controller in the Project Explorer, and double-clickon DefaultAction.

Page 53: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

45

8. From here you will model the implementation of the action. Implementing the Action consists ofdropping steps onto the canvas, configuring the steps, and stringing the steps together into a flow. Thefollowing diagram shows the implementation of the ValidateAppraisal action.

9. In this case there are five steps. Once a step is added the canvas, you can configure the step by double-clicking on the step to open the step properties.

Table 5.9. Action Implementation: ValidateAppraisal Action

Step Name Step Type Properties

Required FieldsSpecified?

Decision

Properties-->Decision Criteria

• Language: Java

• Expression: appraisal.getEmployeeNo() != null&& appraisal.getEmployeeNo() != ""

Set Confirm Page

Invoke Java

Properties-->Java

• Invocation Type: Inline

• Source: page = "/confirm.jsp";

Set Edit Page

Invoke Java

Properties-->Java

• Invocation Type: Inline

• Source: page = "/edit.jsp";

Stop

Stop

Note Optional Text: "This action persists the appraisalto the data source."

Page 54: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

46

Figure 5.21. Properties: Decision Step - Decision Criteria

Figure 5.22. Properties: Invoke Java (Confirm) - Java

Figure 5.23. Properties: Invoke Java (Exit) - Java

10.A Note can be optionally added to an action to describe the functionality of the action.

11.When done, save the action.

Page 55: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

47

1.7. TASK: Add the SaveConfirmedAppraisal Operation

Figure 5.24. Developer View of Application - SaveConfirmedAppraisal

This operation handles the logic when the user clicks on the "Save" button, in which case the validatedappraisal object should be persisted. This action defers to the Save Appraisal operation that was createdin an earlier chapter.

Steps:

1. Right-click on AppraisalEntryController, and select New-->Operation to open the New OperationWizard.

2. From the New Skyway Operation panel, enter "SaveConfirmedAppraisal" for the name. Thiswill be the name of the new operation. The container for this action should be the controller(AppraisalEntryController). If the controller is not highlighted, then select the controller. When done,click Next.

Page 56: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

48

Figure 5.25. SaveConfirmedAppraisal - New Operation Wizard: New SkywayOperation

3. From the Operation Options panel, you are prompted whether a URL mapping should be created forthis operation. A URL Mapping will configure the operation to be available as a web resource using thespecified URL. You are also prompted whether an entry point action should be created. An action isa model-based artifact for implementing the operation logic using Skyway's drag-n-drop steps, whichwill ultimately be generated to Java code in the operation method. For this tutorial accept the alldefaults on the Operation Options panel.

Page 57: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

49

Figure 5.26. SaveConfirmedAppraisal - New Operation Wizard: Operation Options

4. When done, click Finish. This will open the Operation editor.

5. The signature of the operation is specified on the Inputs/Outputs tab. Since the data needed by thisoperation is stored in a controller variable, that is available to all operations defined in the controller,the SaveAppraisal operation doesn't require any input or output parameters.

6. Next you will implement the DefaultAction that is contained within the Operation. Open the actionby expanding the controller in the Project Explorer, and double-click on DefaultAction.

7. From here you will model the implementation of the action. Implementing the Action consists ofdropping steps onto the canvas, configuring the steps, and stringing the steps together into a flow. Thefollowing diagram shows the implementation of the SaveConfirmedAppraisal action.

Page 58: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

50

8. In this case there are only two steps. Once a step is added the canvas, you can configure the step bydouble-clicking on the step to open the step properties.

Table 5.10. Action Implementation: SaveConfirmedAppraisal Action

Step Name Step Type Configuration

Save Appraisal

Invoke Operation

Properties-->Operation

• Operation:PAM.AppraisalService.SaveAppraisal

Properties-->Inputs

• Language: Java

• IInput Variable: inAppraisal - Expression:appraisal

Properties-->Outputs

• None

Stop

Stop

Note Optional Text: "This action persists the appraisalto the data source."

9. A Note can be optionally added to an action to describe the functionality of the action.

2. View - JSP PagesThe user interface is implemented using JSP pages, which were created at the beginning of the chapter.The WebContent folder holds all JSP pages and web-related resources, including javascript libraries,stylesheets, flash controls, and images. Skyway provides a palette of web controls to build user interfaces.The web controls can be wired to the Web Controller and associated Components that were defined inan earlier section. Each web control has it's own properties panel for configuring.

You can further augment Skyway's web controls with the additional functionality available from JSP.

2.1. TASK: Create index.jsp Page

The following figure shows how the index.jsp page will look to the end-user of PAM.

Page 59: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

51

Figure 5.27. index.jsp - runtime view

Steps for creating index.jsp:

1. Right click on WebContent folder of the PAM-Web project, and select New-->JSP. This will open theNew JavaServer Page Wizard.

2. Enter index.jsp as the filename, and click the Next button.

Figure 5.28. index.jsp - New JavaServer Page Wizard: JavaServer Page

3. Select Skyway JSP File (html) as the template, and click the Finish button.

Page 60: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

52

Figure 5.29. index.jsp - New JavaServer Page Wizard: Select JSP Template

4. The pages are comprised of a combination of html and Skyway web controls. Using the Web Controlpalette, build the page according to the following listing. Following the listing there is a description ofkey web controls and their configuration.

• Skyway Form ( <skyway:form> ) - used to define a form. The actionattribute is configured with "${pageContext.request.contextPath}/org/pam/tutorial/web/AppraisalEntryController/InitNewAppraisal.action", the fully qualified path of the operation that willbe invoked when the form is posted.

<skyway:form action="${pageContext.request.contextPath}/org/pam/tutorial/web/AppraisalEntryController/InitNewAppraisal.action" commandName="">...Form Contents...</skyway:form>

• Skyway Button ( <skyway:button> ) - used to provide the user a button to click. The label attributeis configured with "New", the title of the button. To configure the button to submit the form, thetype should be set to "submit".

<skyway:button label="New" type ="submit"></skyway:button>

• Skyway Iterator ( <skyway:iterator> ) - used to define a fragment that should be repeated for asmany objects that exist in the collection. This is very useful for listing the contents of a collection. Theitems attribute is configured with "${appraisals}", the variable collection that should be iterated.When using the "Select..." button in the Properties panel to specify the collection (items), theappraisals variable is located under the LoadAppraisals operation (because we added it as an ouputvariable). The var attribute is configured to "current", a variable that is used by embedded webcontrols (see label) to reference an individual object as the collection is iterated.

<skyway:iterator items="${appraisals}" var="current">

Page 61: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

53

• Skyway Label ( <skyway:label> ) - used to output the value of a variable. The value attribute isconfigured with the variable that should be output. Since this label is referencing a variable froman iterated collection, the variable is referenced as "current.", the var attribute from the iteratorweb control.

<skyway:label value="${current.employeeNo}"></skyway:label>

Figure 5.30. index.jsp - full listing

<%@taglib uri="http://www.skywaysoftware.com/taglibs/core" prefix="skyway"%><%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body><skyway:form action="${pageContext.request.contextPath}/org/pam/tutorial/web/AppraisalEntryController/InitNewAppraisal.action" commandName=""> <skyway:button label="New" type ="submit"></skyway:button></skyway:form>

<table> <tr> <td>Employee No</td> <td>Last Name</td> <td>First Name</td> <td>Design</td> <td>Program</td> <td>Test</td> <td>Comments</td> </tr><skyway:iterator items="${appraisals}" var="current"> <tr> <td><skyway:label value="${current.employeeNo}"></skyway:label></td> <td><skyway:label value="${current.lastName}"></skyway:label></td> <td><skyway:label value="${current.firstName}"></skyway:label></td> <td><skyway:label value="${current.ratingDesign}"></skyway:label></td> <td><skyway:label value="${current.ratingProgramming}"></skyway:label></td> <td><skyway:label value="${current.ratingTesting}"></skyway:label></td> <td><skyway:label value="${current.comments}"></skyway:label></td> </tr></skyway:iterator></table></body></html>

2.2. TASK: Implement edit.jsp Page

The following figure shows how the edit.jsp page will look to the end-user of PAM.

Page 62: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

54

Figure 5.31. edit.jsp - runtime view

Steps for implementing edit.jsp:

1. Create another JSP page called edit.jsp using Skyway JSP File (html) as the template.

2. Using the Web Control palette, build the page according to the following listing. Following the listingthere is a description of key web controls and their configuration.

• Skyway Form ( <skyway:form> ) - used to define a form. The actionattribute is configured with "${pageContext.request.contextPath}/org/pam/tutorial/web/AppraisalEntryController/ValidateAppraisal.action", the fully qualified path of the action that will beinvoked when the form is posted.

<skyway:form action="${pageContext.request.contextPath}/org/pam/tutorial/web/AppraisalEntryController/ValidateAppraisal.action" commandName="appraisal">...Form Contents...</skyway:form>

• Skyway Input ( <skyway:input> ) - used to solicit input from the user. The path attribute is the pathof the variable that the contents of the input field should be stored.

<skyway:input type="text" id="input_RVkXsl" designPath="PAM.AppraisalEntryController.ValidateAppraisal" path="employeeNo"></skyway:input>

• kyway Dropdown ( <skyway:dropdown> ) - used to let the user select one of multiple preset values.The path attribute is the path of the variable that the contents of the selected value should be stored.

<skyway:dropdown path="ratingDesign" controller="" designPath="PAM.AppraisalEntryController.ValidateAppraisal">...options...</skyway:dropdown>

• Skyway Option ( <skyway:option> ) - used to specify a preset value for the dropdown control. Thelabel attribute is displayed to the end user, and the value attribute is the value that's submittedfor the option.

<skyway:option label="Exceeds Expectations" value="1"></skyway:option><skyway:option label="Meets Expectations" value="2"></skyway:option><skyway:option label="Does Not Meet Expectations" value="3"></skyway:option>

• Skyway Textarea ( <skyway:textarea> ) - used to solicit input from the user. The path attribute is thepath of the variable that the contents of the input field should be stored.

Page 63: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

55

<skyway:textarea path="comments" controller="" designPath="PAM.AppraisalEntryController.ValidateAppraisal"></skyway:textarea>

• Skyway Button ( <skyway:button> ) - used to provide the user a button to click. The label attributeis configured with "Save", the title of the button. To configure the button to submit the form, thetype should be set to "submit".

<skyway:button type="submit" label="Next" ></skyway:button>

Figure 5.32. edit.jsp - full listing

<%@ page language="java" isELIgnored="false" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><%@taglib uri="http://www.skywaysoftware.com/taglibs/core" prefix="skyway"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title><skyway:javascript src="prototype.js"/><skyway:javascript src="skyway-internal.js"/><skyway:javascript src="skyway.js"/></head><body><skyway:form action="${pageContext.request.contextPath}/org/pam/tutorial/web/AppraisalEntryController/ValidateAppraisal.action" commandName="appraisal"> Employee No <skyway:input type="text" id="input_RVkXsl" designPath="PAM.AppraisalEntryController.ValidateAppraisal" path="employeeNo"></skyway:input> <br> Last Name <skyway:input type="text" id="input_cicoAF" designPath="PAM.AppraisalEntryController.ValidateAppraisal" path="lastName"></skyway:input> <br> First Name <skyway:input type="text" id="input_y6WNC1" designPath="PAM.AppraisalEntryController.ValidateAppraisal" path="firstName"></skyway:input>

<h2>Ratings:</h2> Design <skyway:dropdown path="ratingDesign" controller="" designPath="PAM.AppraisalEntryController.ValidateAppraisal"> <skyway:option label="Exceeds Expectations" value="1"></skyway:option> <skyway:option label="Meets Expectations" value="2"></skyway:option> <skyway:option label="Does Not Meet Expectations" value="3"></skyway:option> </skyway:dropdown><br> Programming <skyway:dropdown path="ratingProgramming" controller="" designPath="PAM.AppraisalEntryController.ValidateAppraisal"> <skyway:option label="Exceeds Expectations" value="1"></skyway:option> <skyway:option label="Meets Expectations" value="2"></skyway:option> <skyway:option label="Does Not Meet Expectations" value="3"></skyway:option> </skyway:dropdown><br> Testing <skyway:dropdown path="ratingTesting" controller="" designPath="PAM.AppraisalEntryController.ValidateAppraisal"> <skyway:option label="Exceeds Expectations" value="1"></skyway:option> <skyway:option label="Meets Expectations" value="2"></skyway:option> <skyway:option label="Does Not Meet Expectations" value="3"></skyway:option> </skyway:dropdown> <br> Comments: <skyway:textarea path="comments" controller="" designPath="PAM.AppraisalEntryController.ValidateAppraisal"></skyway:textarea> <br> <skyway:button type="submit" label="Next" ></skyway:button> </skyway:form></body></html>

Page 64: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

56

2.3. TASK: Implement confirm.jsp Page

The following figure shows how the confirm.jsp page will look to the end-user of PAM.

Figure 5.33. confirm.jsp - runtime view

Steps for implementing confirm.jsp:

1. Create another JSP page called confirm.jsp using Skyway JSP File (html) as the template

2. Using the Web Control palette, build the page according to the following listing. Following the listingthere is a description of key web controls and their configuration.

• Skyway Form ( <skyway:form> ) - used to define a form. The actionattribute is configured with "${pageContext.request.contextPath}/org/pam/tutorial/web/AppraisalEntryController/SaveConfirmedAppraisal.action", the fully qualified path of the action thatwill be invoked when the form is posted.

<skyway:form action="${pageContext.request.contextPath}/org/pam/tutorial/web/AppraisalEntryController/SaveConfirmedAppraisal.action" commandName="">...form...</skyway:form>

• Skyway Button ( <skyway:button> ) - used to provide the user a button to click. The label attributeis configured with "Save", the title of the button. To configure the button to submit the form, thetype should be set to "submit".

<skyway:button type="submit" label="Save" id="button_0n5lNx"></skyway:button>

• Skyway Label ( <skyway:label> ) - used to output the value of a variable. The value attribute isconfigured with the variable that should be output.

<skyway:label value="${appraisal.firstname}" controller="AppraisalEntryController" designPath="PAM.AppraisalEntryController"></skyway:label>

Page 65: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

57

Figure 5.34. confirm.jsp - full listing<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><%@taglib uri="http://www.skywaysoftware.com/taglibs/core" prefix="skyway"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title><skyway:javascript src="prototype.js"/><skyway:javascript src="skyway-internal.js"/><skyway:javascript src="skyway.js"/></head><body>

Please confirm this appraisal for:<br><skyway:label value="${appraisal.firstName}" controller="AppraisalEntryController" designPath="PAM.AppraisalEntryController"></skyway:label><skyway:label value="${appraisal.lastName}" controller="AppraisalEntryController" designPath="PAM.AppraisalEntryController"></skyway:label> <br><br><skyway:form action="${pageContext.request.contextPath}/org/pam/tutorial/web/AppraisalEntryController/SaveConfirmedAppraisal.action" commandName=""> <skyway:button type="submit" label="Save" id="button_0n5lNx"></skyway:button></skyway:form>

</body></html>

2.4. TASK: Configure URL MappingsIn addition to serving as the container Operations, a Web Controller has the very important functionof associating urls to operations and views, and this is referred to as a URL Mapping. As you createOperations in a Controller, you must decide whether the Operation is going to be accessible using a URL.In order for the action to be accessible from a JSP page in a Skyway application or any other web client,the action must be configured as web resource, and this is accomplished by adding an URL mapping inthe Web Controller.

A URL mapping is responsible for defining the url(s) that will trigger an operation. When the defined URLis requested from a web control, javascript or web client, the operation mapped to the url will handlethe request. The URL mapping will also specify the jsp that will render the response to the request. Everyrequest will have a response, and the URL mapping specifies both the operation that will handle therequest and the jsp that will render the response.

Earlier in the tutorial there were several Operations that were added to "AppraisalEntryController" , andeach operation is responsible for handling a particular task. When the Operations were created, you wereprompted whether to "Create a URL Mapping". For every New Operation wizard where you left the optionenabled (default), a new URL Mapping entry was added to AppraisalEntryController.

You may be wondering what's the association between the URL and the Operation, particularly since theOperation name is embedded in some of the mapping URLs. The answer is that there's no association,other than an association specified by the developer or created by default (although it can be overridden)in the "New Operation" wizard. The association between URLs and Operations is completely up to thedeveloper. By convention the new Operation Wizard will define a URL Mapping partly based on the nameof the controller and operation.

During the course of the tutorial four URL mappings were automatically created. For three of theURL mappings (InitNewAppraisal, ValidateAppraisal, and SaveConfirmedAppraisal) the only remaining

Page 66: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

58

configuration is to associate the mapping with a view. For the LoadAppraisals URL mapping, you mustalso change the URL to /index.jsp, the entry point of the web application. Any calls to /index.jsp will fallunder this action mapping.

Figure 5.35. URL Mapping

Here's a listing and description of each URL mapping:

• (#1) When the end-user initiates the application (index.html), there is some application initializationthat needs to occur. In an earlier step of the tutorial, the LoadAppraisals operation was implemented toperform the initialization, and it must be executed prior to index.jsp being rendered. This accomplishedby mapping "/index.html" to the LoadAppraisals operation. When the operation is complete, the "/index.jsp" page renders the response (or view).

• (#2) When the end-user clicks on the "New" button, there is some initialization that must occur (theInitNewAppraisal operation) prior to rendering the edit.jsp. The URL mapping is implemented bymapping the "/org/pam/tutorial/web/AppraisalEntryController/InitNewAppraisal.action" URL to theInitNewAppraisal action. When the action is complete, the "/edit.jsp" page renders the response (orview).

• (#3) When the end-user clicks on the "Next" button, there is some data validation that must occur (theValidateAppraisal operation), and the page will be determined (either /edit.jsp or /confirm.jsp) basedon the results of the validation. The URL mapping is implemented by mapping the "/org/pam/tutorial/web/AppraisalEntryController/ValidateAppraisal.action" URL to the ValidateAppraisal operation. Theview is explicity set in the implementation of the operation using the page variable, the view settingfor the URL mapping references the page variable.

• (#4) When the end-user clicks on the "Save" button, the appraisal must be actuallypersisted (the SaveConfirmedAppraisal action) prior to rendering the index.jsp page. TheURL mapping is implemented by mapping the "/org/pam/tutorial/web/AppraisalEntryController/

Page 67: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

59

SaveConfirmedAppraisal.action" URL to the SaveConfirmedAppraisal action. When the action iscomplete, a redirect is sent to the "/index.html" URL, which starts the process all over again. (Goto #1)

Steps:

1. URL Mappings are configured in the Web Controller. If the AppraisalEntryController isn't already open,double click on it to open the Web Controller editor.

2. From the URL Mapping tab, the following mappings in the following table should be configured. Theentries should have been automatically created when the operations were created. All the entries willneed to be configured with the specified View, and the URL for the LoadAppraisals entry should bechanged to "/index.html" to have the operation executed on entry to the index. page.

Table 5.11. AppraisalEntryController: URL Mappings

URL Request Handler View

/index.html Operation:

PAM.AppraisalEntryController.

LoadAppraisals

/index.jsp

/org/pam/tutorial/web/AppraisalEntryController/InitNewAppraisal.action

Operation:

PAM.AppraisalEntryController.

InitNewAppraisal

/edit.jsp

/org/pam/tutorial/web/AppraisalEntryController/ValidateAppraisal.action

Operation:

PAM.AppraisalEntryController.

ValidateAppraisal

${page}

/org/pam/tutorial/web/AppraisalEntryController/SaveConfirmedAppraisal.action

Operation:

PAM.AppraisalEntryController.

SaveConfirmedAppraisal

/index.html(redirect)

Page 68: Skyway Builder 6.3 - Spring MVC Tutorial

Web Layer

60

Figure 5.36. AppraisalEntryController - Web Controller Editor: URL Mapping

Page 69: Skyway Builder 6.3 - Spring MVC Tutorial

61

Chapter 6. Deployment

Here is a brief description of the setup of the runtime environment. This topic is described in greater detailin the Sandbox Setup guide that is available in the Resources section of the Skyway Community Portal1.

1. Configure Database

1.1. Add Data SourceIn Eclipse you will add a data source that you will use for your running applications. This can be doneusing the Data Source Explorer view in Eclipse.

1.2. Configure Data Access Object in ProjectFor the AppraisalDAO Data Access Object in the project, go to Database Configuration tab and configurethe database connection with the data source you created in the Data Source Explorer.

2. Configure Server

2.1. Add ServerIn Eclipse you will add a Server that you will use for your running applications. This can be done usingthe Servers view in Eclipse.

2.2. Add PAM Project to ServerThe project can be added to the server by right-clicking on the Server at selecting the "Add and RemoveProjects" menu item. The PAM project should be added to the server.

3. Run Application

3.1. Start ServerWhen you start the server, the application should be deployed to the server.

3.2. Run ApplicationRight-click on the index.jsp in PAM-Web, and select "Run On Server".

1 http://www.skywayperspectives.org

Page 70: Skyway Builder 6.3 - Spring MVC Tutorial

Deployment

62

Alternatively you can use the following URL: http://localhost:8080/PAM-Web/index.html2

If you get stuck or need help, there is a forum on the Skyway Community portal dedicated to the SkywayTutorials3.

2 http://localhost:8080/PAM-Web/appraisalentry3 www.skywayperspectives.org/portal/web/guest/174/message_boards/category/10960


Recommended