spring web flow tutorial skyway software skyway · pdf filedevelopment process ..... 6 9.1....

59
Skyway Builder 6.3 - Spring Web Flow Tutorial 6.3.0.0 - 07/21/2009 Skyway Software

Upload: ledang

Post on 11-Mar-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

Skyway Builder 6.3 -Spring Web Flow Tutorial

6.3.0.0 - 07/21/2009

Skyway Software

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

PublishedCopyright © 2008 Skyway Software

Abstract

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

2 http://www.skywayperspectives.org

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. Flow .................................................................................................................... 30

1.1. TASK: Add org.pam.tutorial.web Model Package ............................................... 301.2. TASK: Add appraisalentry Web Flow ............................................................... 311.3. TASK: Add Instance Variables ......................................................................... 331.4. TASK: Add listappraisals View State ................................................................. 341.5. TASK: Add edit View State ............................................................................ 361.6. TASK: Add validate Decision State .................................................................. 371.7. TASK: Add confirm View State ....................................................................... 391.8. TASK: Add save Action State .......................................................................... 40

2. View - JSP Pages .................................................................................................... 422.1. TASK: Create listappraisals.jsp Page ................................................................ 422.2. TASK: Implement edit.jsp Page ...................................................................... 452.3. TASK: Implement confirm.jsp Page ................................................................. 47

6. Deployment .................................................................................................................. 501. Configure Database ................................................................................................ 50

1.1. Add Data Source ......................................................................................... 501.2. Configure Data Access Object in Project .......................................................... 50

2. Configure Server .................................................................................................... 502.1. Add Server ................................................................................................. 502.2. Add PAM Project to Server ........................................................................... 50

Skyway Builder 6.3 -Spring Web Flow Tutorial

v

3. Run Application ..................................................................................................... 503.1. Start Server ................................................................................................ 503.2. Run Application .......................................................................................... 50

vi

List of Figures1.1. Project Meta-Data Model ............................................................................................... 21.2. End-User View of Application .......................................................................................... 41.3. Developer View of Application (Web Flow Diagram) ............................................................ 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 ..................................... 315.2. appraisalentry - New Web Flow Wizard: New Web Flow ..................................................... 325.3. appraisalentry - New Web Flow Wizard: Create Webflow Domain Model ............................... 335.4. appraisalentry - Web Flow Editor (Blank) ......................................................................... 335.5. AppraisalEntryController - Controller Editor: Variables ........................................................ 345.6. Adding Events ............................................................................................................. 355.7. listappraisals - On Entry Action Block .............................................................................. 355.8. listappraisals - Evaluate Action ....................................................................................... 365.9. edit - On Entry Action Block .......................................................................................... 375.10. Transition - listappraisals to edit ................................................................................... 375.11. validate - If Expression ............................................................................................... 385.12. Adding Events ........................................................................................................... 385.13. Transitions - edit to validate ........................................................................................ 395.14. Transition - listappraisals to edit ................................................................................... 405.15. save - Complete ........................................................................................................ 415.16. save - Complete ........................................................................................................ 41

Skyway Builder 6.3 -Spring Web Flow Tutorial

vii

5.17. PAM - Web Flow Diagram ........................................................................................... 415.18. listappraisals.jsp - runtime view ................................................................................... 425.19. listappraisals.jsp - New JavaServer Page Wizard: JavaServer Page ........................................ 435.20. listappraisals.jsp - New JavaServer Page Wizard: Select JSP Template ................................... 435.21. listappraisals.jsp - full listing ........................................................................................ 455.22. edit.jsp - runtime view ............................................................................................... 455.23. edit.jsp - full listing .................................................................................................... 475.24. confirm.jsp - runtime view .......................................................................................... 485.25. confirm.jsp - full listing ............................................................................................... 49

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. Flow Instance Variables ................................................................................................ 345.2. View State - listappraisals ............................................................................................. 345.3. listappraisals - On Entry Actions ..................................................................................... 355.4. View State - edit ......................................................................................................... 365.5. listappraisals - On Entry Actions ..................................................................................... 365.6. Decision State - validate ............................................................................................... 385.7. Decision State - If Expression ........................................................................................ 385.8. View State - confirm .................................................................................................... 395.9. Action State - save ...................................................................................................... 405.10. save - Action Block .................................................................................................... 40

1

Chapter 1. Introduction

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

The Spring Web Flow tutorial will re-use portions of the Spring MVC tutorial, specifically the data andservice layers. Therefore Chapters 2 thru 4 of both tutorials are identical. If you've already completed theSpring MVC 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, Spring WebFlow and Eclipse. It is assumed that the developer has basic experience with running a JEE ApplicationServer and a database management 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 Web Flow applicationusing Skyway Builder. This tutorial isn't making use of any Skyway Builder Enterprise Edition features.So this tutorial is applicable to all versions of Skyway Builder, Community Edition (open source) andEnterprise Edition. While the sample application is intentionally limited in scope, it introduces new usersto application 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

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

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.

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 Spring DSL artifacts for implementing the web layer of a SpringMVC application are the Controller, Operation, Component, Action, Steps and JSP pages. The Spring DSLartifacts 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 Web Flow application.)

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.

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 Spring DSL 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.

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 (Web Flow Diagram)

Developer View of Application using Skyway Builder

• Step 1: Prior to the listappraisals view state (listappraisals.jsp) rendering, there is some data loadingthat needs to occur. This is accomplished using an On Entry event that calls the findAllAppraisals namedquery, and the results are stored in a flowScoped variable called appraisals.

• Step 2: The "New Appraisal" hyperlink on the listappraisals.jsp page is configured to generate a newevent, which will direct the user to the edit view state (edit.jsp). Prior to the view state rendering, anew appraisal object needs to be initialized. This is accomplished using an On Entry event that sets aflow variable called appraisal to "new org.pam.tutorial.domain.Appraisal();" .

• Step 3: The end-user will press the "Next" button when finished filling in the appraisal form. The "Next"button is configured to generate a next event, which will direct the flow to the decision state calledvalidate, that will verify that all the required information was entered by the end-user. If all the requiredinfo is specified, the end-user will be directed to either the confirm view state (confirm.jsp). Otherwisethe end user will return to the edit view state.

• Step 4: The "Confirm" button on the confirm.jsp page is configured to generate a save event, whichwill flow to the save action state and call the SaveAppraisal service.

• Step 5: Upon completion of the save, theend-user will be directed back to the listappraisals view state.

Use the following Project Exploter screenshot as a guideline for implementing the project. This screenshotalso shows the AppraisalEntryController that is part of the Spring MVC implementation of PAM, but it'snot required for the Spring Web Flow implementation.

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.

Introduction

7

High-level Development Steps Defined

• Project - create a project

• Data Layer - define the data layer

• Services Layer - define the service layer

• Web Layer - define the web layer

• Deploy - deploy the project

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:

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

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

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.

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.

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

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.

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.

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

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.

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.

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

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.

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.

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.

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

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.

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.

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.

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.

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

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

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 of a Spring Web Flow application are Web Flows and JSP pages. A Spring MVC application uses adifferent set of artifacts (see the Skyway Builder 6.3 - Spring MVC Tutorial).

This chapter will outline the steps for implementing the web layer of PAM using Spring Web Flow.

1. Flow

1.1. TASK: Add org.pam.tutorial.web 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 are typically generatedinto a 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.

Web Layer

31

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

3. When done, click Finish.

1.2. TASK: Add appraisalentry Web Flow

As described earlier Web Flows are used along with the JSP pages (located in the WebContent) toimplement the Web layer of an application. The JSP pages represent the View in the web layer, and WebFlows handle the orchestration of the web application.

Steps:

1. Create a folder for storing the flow domain model. In the WEB-INF folder create a folder called flows.In the flows folder create a folder called appraisalentry. The new flow will be stored in WebContent\WEB-INF\flows\appraisalentry.

2. Right click on org.pam.tutorial.web project, and select New-->Web Flow

3. From the New Web Flow Wizard, enter "appraisalentry" for the filename. This will be the name ofthe web flow diagram. The container for this flow should be the project (PAM). If the project is nothighlighted, then select the project. When done, click Next.

Web Layer

32

Figure 5.2. appraisalentry - New Web Flow Wizard: New Web Flow

4. From the Create Webflow Domain Model panel, you are prompted for the name and location of thedomain model. As you make changes to the web flow diagram, the flow domain model will be updatedwith Spring Web Flow specific content. The domain model is what's deployed with your applicationand interpretted by the Spring Web Flow framework. That's why it must be located in the directorycreated in step 1.

Web Layer

33

Figure 5.3. appraisalentry - New Web Flow Wizard: Create Webflow Domain Model

5. When done, click Finish. This will open the Web Flow editor.

Figure 5.4. appraisalentry - Web Flow Editor (Blank)

1.3. TASK: Add Instance VariablesInstance variables are variables that are allocated when the flow starts, and they are for specifying datathat can be shared across all steps in a flow. For PAM we need a single instance variable for storing theappraisal being entered.

Steps:

1. From the Flow configuration element, add an Instance variable (Variables) according to the followingtable. Variables are added by press the + symbol beside Variables.

Web Layer

34

Table 5.1. Flow Instance Variables

Name Class

appraisal org.pam.tutorial.domain.Appraisal

2. Figure 5.5. AppraisalEntryController - Controller Editor: Variables

3.

1.4. TASK: Add listappraisals View State

A View state defines a step of the flow that renders a view, and the view state is configured with theJSP that will render the view. The first view of the application is listappraisals that will display a tableof previously save appraisals. However before listappraisals can be rendered, the appraisal data must beloaded. This is accomplished by setting an On Entry event on the view state that will make a direct callto the DAO to retrieve the data.

The listappraisals view state is configured with the JSP that will render the view. The actualimplementation of the JSP will be covered in a later section.

Steps:

1. Click on the View State in the Web Flow States drawer of the Web Flow palette, and then click on thelocation of the flow diagram where you want to place it.

2. Configure the View State according the following table

Table 5.2. View State - listappraisals

Relevant Attributes Configuration Description

Name listappraisals

View listappraisals.jsp the jsp that will render the view

3. Next you need to add an On Entry event to listappraisals view state. Start by clicking on the Eventarrow from the Web Flow palette. Next single click on the view state you want to add an entry eventto, and then click anywhere outside the view state. You will be presented with a list of events thatare available to the selected state. In the case of a View State, you can add an On Entry, On Renderand On Exit events..

Web Layer

35

Figure 5.6. Adding Events

4. Click on the Create On Entry Event. An action block will be placed on the diagram, and it is used fordefining any on entry actions you want to perform. The action block can relocated by dragging to otherareas of diagram.

Figure 5.7. listappraisals - On Entry Action Block

5. At the top right hand corner of an action block are three icons for adding adding either evaluate, set orrender actions. For listappraisals you need to add an evaluate action (first icon), and the action needsto be configured according to the following table:

Table 5.3. listappraisals - On Entry Actions

Action Type Configuration

evaluate Expression: AppraisalDAO.findAllAppraisals(0,-1)

Result: flowScope.appraisals

Type: <blank>

Web Layer

36

Figure 5.8. listappraisals - Evaluate Action

6. The listappraisals View State has been configured.

1.5. TASK: Add edit View StateThe second step of the flow is another View State called edit, which is where the end-user will beprompted to enter the details of a new appraisal. Prior to the view state rendering, a new appraisal objectneeds to be initialized. This is accomplished using by setting an On Entry event on the view state, verysimilar to the listappraisals state.

The edit view state isn't configured with a JSP to render the view. If a JSP isn't specified, Spring WebFlow will by default find and use a JSP with the same name in the same folder that the flow domainmodel (appraisalentry.xml) is located. This is great example of Spring Web Flow's use of convention overconfiguration. Of course if you want to use a different JSP, you can configure it. The actual implementationof the edit.jsp will be covered in a later section.

Steps:

1. Click on the View State in the Web Flow States drawer of the Web Flow palette, and then click on thelocation of the flow diagram where you want to place it.

2. Configure the View State according the following table

Table 5.4. View State - edit

Relevant Attributes Configuration Description

Name edit

3. Next you need to add an On Entry event to the edit view state. Refer back to listappraisals view statefor detailed instructions on adding and configuring On Event actions.

4. Add the following actions to the On Entry action block.

Table 5.5. listappraisals - On Entry Actions

Action Type Configuration

set Name: appraisal

Web Layer

37

Action Type Configuration

Value: new org.pam.tutorial.domain.Appraisal()

Type: <blank>

Figure 5.9. edit - On Entry Action Block

5. The edit View State has been configured. While there are still more steps in the flow, now is a goodtime to define the transitions in the listappraisals state that will navigate the end-user to the edit state.To add a transition, click on the Transition arrow from the Web Flow palette. Next single click on thelistappraisals state and then click on the edit state. This will create a transition line between the twostates to represents the transition. The only left to configure is the event id for this transition. Webcontrols on the JSP that render a View State are configured to fire events (using an event id) as theend-user interacts with the application. Spring Web Flow uses the event ids to determine the flowof the application. The event id for this transition line is called new. Therefore the event id on thetransition line should be new.

Figure 5.10. Transition - listappraisals to edit

1.6. TASK: Add validate Decision State

A Decision state is a step for routing the flow based on the result of an if/else expression. In PAM a decisionstate will be used to verify that an employee number was entered by the end-user. If so, the decision statewill progress to the next step of the flow (confirm). If not, the decision state will return to the edit state.

Web Layer

38

Steps:

1. Click on the Decision State in the Web Flow States drawer of the Web Flow palette, and then click onthe location of the flow diagram where you want to place it.

2. Configure the Decision State according the following table

Table 5.6. Decision State - validate

Relevant Attributes Configuration Description

Name validate

3. Next you will need to an if expression to the decision state. If expressions are added by press the +symbol beside If. Configure the if expression according the following table:

Table 5.7. Decision State - If Expression

Expression

appraisal.employeeNo != ""

Figure 5.11. validate - If Expression

4. The validate Decision State has been configured. Next add a next transition from edit to validate states.In the scenario where the decision state expression evaluates to false, you also need to configure thedecision states else transition to edit state. When you configure a transition from a decision state,you won't be prompted to type in an event id. Instead you will presented with an option for each ifexpression added to the decision state and an else option.

Figure 5.12. Adding Events

Web Layer

39

Figure 5.13. Transitions - edit to validate

1.7. TASK: Add confirm View State

The fourth step of the flow is another View State called confirm, which is where the end-user will be askedto reverify the data they've entered (that has passed validation by the application) prior to persisting itto the database.

The confirm view state isn't configured with a JSP to render the view. Spring Web Flow will look for a JSPcalled confirm.jsp in the same folder as the flow domain model (appraisalentry.xml) is located.

Steps:

1. Click on the View State in the Web Flow States drawer of the Web Flow palette, and then click on thelocation of the flow diagram where you want to place it.

2. Configure the View State according the following table

Table 5.8. View State - confirm

Relevant Attributes Configuration Description

Name confirm

3.

4. The confirm View State has been configured. Next add another transition from the validate state tothe confirm state. There is only one remaining transition line available from the decision state, and itcorresponds to the if expression (appraisal.employeeNo != "").

Web Layer

40

Figure 5.14. Transition - listappraisals to edit

1.8. TASK: Add save Action State

An Action state is a step for invoking an action and routing to another state based on the result of theaction. For the PAM application, the Action State will persist the flow using the SaveAppraisal operationdefined earlier in the tutorial. Upon completion, the Action State will transition to the listappraisals state.

Steps:

1. Click on the Action State in the Web Flow States drawer of the Web Flow palette, and then click onthe location of the flow diagram where you want to place it.

2. Configure the Action State according the following table

Table 5.9. Action State - save

Relevant Attributes Configuration Description

Name save

3. At the top right hand corner of an action state element three are icons for adding adding eitherevaluate, set or render actions. For save step need to add an evaluate action (first icon), and the actionneeds to be configured according to the following table:

Table 5.10. save - Action Block

Action Type Configuration

evaluate Expression:AppraisalService.saveAppraisal(appraisal)

Result: <blank>

Type: <blank>

Web Layer

41

Figure 5.15. save - Complete

4. The save Action State has been configured. There are still two transitions that need to be configured.Add a save transition from confirm state to save state, and add a success transition from the savestate to listappraisals state.

Figure 5.16. save - Complete

5. The flow is complete and can be save. If you prefer you can change the background colors for each ofthe steps. Here's the completed flow diagram.

Figure 5.17. PAM - Web Flow Diagram

Web Layer

42

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 listappraisals.jsp Page

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

Figure 5.18. listappraisals.jsp - runtime view

Steps for creating listappraisals.jsp:

1. Right click on WebContent\WEB-INF\flows\appraisals folder of the PAM-Web project, and selectNew-->JSP. This will open the New JavaServer Page Wizard.

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

Web Layer

43

Figure 5.19. listappraisals.jsp - New JavaServer Page Wizard: JavaServer Page

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

Figure 5.20. listappraisals.jsp - New JavaServer Page Wizard: Select JSP Template

Web Layer

44

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 action attribute is configured with"{flowExecutionUrl}", a Spring Web Flow variable that resolves to the URI of the current view state.

<skyway:form action="${flowExecutionUrl}" commandName="">...Form Contents...</skyway:form>

• HTML Input ( <input> ) - used to provide the user a button to click. The type should be set to"submit". The value attribute is configured with "New", the title of the button. To configure thebutton to fire the new event that was defined for the listappraisals state, the name should be setto "_eventId_new".

<input type="submit" name="_eventId_new" value="New" />

• 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 flowScope variable that was defined in theOn Entry event for storing the results of the findAllAppraisals query. The var attribute is configuredto "current", a variable that is used by embedded web controls (see label) to reference an individualobject as the collection is iterated.

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

• 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>

Web Layer

45

Figure 5.21. listappraisals.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="${flowExecutionUrl}" commandName=""> <input type="submit" name="_eventId_new" value="New" /> </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.

Figure 5.22. edit.jsp - runtime view

Web Layer

46

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 action attribute is configured with"{flowExecutionUrl}", a Spring Web Flow variable that resolves to the URI of the current view state.The commandName is configured with appraisal, the instance variable that was created in the flowthat represents the command object for this form.

<skyway:form action="${flowExecutionUrl}" 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 field should be bound to. It should be an attribute of the command objectconfigured on the form. (i.e. appraisal.employeeNo)

<skyway:input path="employeeNo"></skyway:input>

• Skyway 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 field should be bound to. Once again, it shouldbe an attribute of the command object configured on the form. (i.e. appraisal.ratingDesign) .

<skyway:dropdown path="ratingDesign">...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 field should be bound to. (i.e. appraisal.comments)

<skyway:textarea path="comments"></skyway:textarea>

• HTML Input ( <input> ) - used to provide the user a button to click. The type should be set to"submit". The value attribute is configured with "Next", the title of the button. To configure thebutton to fire the next event that was defined for the listappraisals state, the name should be setto "_eventId_next".

<input type="submit" name="_eventId_next" value="Next" />

Web Layer

47

Figure 5.23. 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="${flowExecutionUrl}" commandName="appraisal"> Employee No <skyway:input path="employeeNo"></skyway:input> <br> Last Name <skyway:input path="lastName"></skyway:input> <br> First Name <skyway:input path="firstName"></skyway:input> <h2>Ratings:</h2> Design <skyway:dropdown path="ratingDesign"> <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"> <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"> <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"></skyway:textarea> <br> <input type="submit" name="_eventId_next" value="Next" /> </skyway:form></body></html>

2.3. TASK: Implement confirm.jsp Page

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

Web Layer

48

Figure 5.24. 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 action attribute is configured with"{flowExecutionUrl}", a Spring Web Flow variable that resolves to the URI of the current view state.

<skyway:form action="${flowExecutionUrl}" commandName="">...form...</skyway:form>

• HTML Input ( <input> ) - used to provide the user a button to click. The type should be set to"submit". The value attribute is configured with "Nexy", the title of the button. To configure thebutton to fire the next event that was defined for the listappraisals state, the name should be setto "_eventId_next".

<input type="submit" name="_eventId_save" value="Save" />

• Skyway Label ( <skyway:label> ) - used to output the value of a variable. The value attribute isconfigured with the variable that should be output. This label is referencing a flow-scoped variablecalled appraisal.

<skyway:label value="${appraisal.firstName}"></skyway:label>

Web Layer

49

Figure 5.25. 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}"></skyway:label><skyway:label value="${appraisal.lastName}"></skyway:label> <br>

<skyway:form action="${flowExecutionUrl}" commandName=""> <input type="submit" name="_eventId_save" value="Save" /> </skyway:form>

</body></html>

50

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 ApplicationHere's the URL for the application: http://localhost:8080/PAM-Web/appraisalentry

1 http://www.skywayperspectives.org

Deployment

51

Note: The url for the Spring Web Flow implementation is different from the url of the Spring MVCimplementation.

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

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