Jon Perry's Blog

Spring Web Flow – using Eclipse IDE (Tutorial)

I’ve been looking online lately for tutorials on Spring Web Flow, and I didn’t find any that were succinct, memorable, or very appealing. For every tutorial that you find online, that framework may be out of date, and another may be in date; but be horrendously long to read… This article helps challenge these attributes.

For this tutorial I am using:

IDE: Eclipse (Java EE)
Build tool: Maven
Framework: Spring v4 << the important bit ... and Java, obviously.

Step 1:

Create a new project in Eclipse. You’ll need to open ‘other’ option under the New menu heading. A new window will open – select Maven -> Maven Project.

Step 2:

Setup your Spring dependencies.

When you create a new Maven project (under File -> New -> Other…), you will need to use your default workspace location, using the ‘maven-archetype-webapp’ artifact ID. Give your Maven project a name, followed by the parent package that you want to create for this project.

Open the pom.xml file under the root of your application’s directory.

With your pom.xml configuration file open, you’ll need to specify to Maven what Java libraries your application will need to build, deploy and run.

To create a Spring Web Flow application, we’ll need three components belonging to the Spring framework, those being: Spring Core, Spring MVC and Spring Web Flow. We will also need Spring Boot, Spring Web, Spring Context and Spring Autoconfigure.

The framework itself isn’t one dependency, more-over is an assortment of components, (I presume) for the purpose of modularity and performance.

<!-- Spring Boot -->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot</artifactId>
   <version>1.2.3.RELEASE</version>
</dependency>
       
<!-- Spring Web -->
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-web</artifactId>
   <version>4.1.6.RELEASE</version>
</dependency>
       
<!-- Spring Core -->
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-core</artifactId>
   <version>4.1.6.RELEASE</version>
</dependency>
       
<!-- Spring MVC -->
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>4.1.6.RELEASE</version>
</dependency>
   
<!-- Spring Web Flow -->
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webflow</artifactId>
   <version>1.0.6</version>
</dependency>
   
<!-- Spring Context -->
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context</artifactId>
   <version>4.1.6.RELEASE</version>
</dependency>
   
<!-- Spring AutoConfigure -->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-autoconfigure</artifactId>
   <version>1.2.3.RELEASE</version>
</dependency>

Figure 1. Maven dependencies – feel free to copy n’ paste!

Step 2: Write code like MVC… not ABC…

We’ve got the important stuff out of the way. We can now focus on writing our Java code!

To begin with, we’re going to write the root of our application.

Start by creating a new Java class and name it something like Application. This will allow us to compile and execute the application on our local Tomcat server.

package com.learning.spring.webflow;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
   
   public static void main(String [] args) {
      SpringApplication.run(Application.class, args);
   }

}

This very small and simple class simply instructs the Spring boot component to execute our code against the JVM.

Next, we need to create a class which will act as the Controller (eventually) in our Spring Web Flow application.

// Spring MVC component
import org.springframework.stereotype.Controller;

// Spring Web component
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HolidayBookingFormController {

   @RequestMapping("/book-holiday-date")
   public String holidayChooseDates() {
     
   }

   @RequestMapping("/book-holiday-guests")
   public String holidayNumberOfGuests() {
     
   }

   @RequestMapping("/book-holiday-flights")
   public String holidayChooseFlights() {
     
   }

   @RequestMapping("/book-holiday-extras")
   public String holidayChooseExtras() {
     
   }

   @RequestMapping("/book-holiday-insurance")
   public String holidayConfirmBooking() {
     
   }

}

For each of the methods contained within this controller, each HTTP request maps (corresponds) with the JSP that will handle the presentation of our application.

Step 3: Create the JSP’s!

New Hobby…

So… we are 25 days into the New Year. It’s been ok, and despite the cold, things are going generally, ‘ok’.

For a long time, I’ve been exploring and developing experience in different disciplines encompassing Computer Science (mainly to get a job in software engineering), but I haven’t had time to explore a topic where I can unleash my creativity, never get bored technically, and generally enjoy a hobby with a lot of pleasure attached to it. That topic, is Computer Graphics!

I can’t wait to see how things develop. I’m going to make loads of mistakes, and probably adopt some bad practices (by mistake) at some stage, but I can’t wait to show the world what I do. I’ve been exposed to art, design and technical disciplines through my life and I really relish doing something a lot of Computer Science professionals never sadly explore in their spare time alongside a full time job.

Happy New Year!

It’s been quite a while since I last posted something on this blog. In that time I have finished my MSc and started a new job in the real world. In the spirit of the New Year and Resolutions, I have recently created my own custom theme for this blog (ooh er!).

The hope behind the change in the design is to put myself into a more focused, professional mindset, so I can use this little space on the inter-web to share my technical creations in my spare time, now that I am working in the commercial world of technology 🙂

Watch this space…

Dissertation Progress – Day 67

Tasks complete today:

  1. Coded intial monitoring system component – will implement Fuzzy Logic system tomorrow.
  2. Read paper ‘The Computer for the 21st Century’.

Dissertation Progress – Day 66

Tasks complete today:

  1. Printed Project Report (draft)
  2. Printed System Evaluation questionnaire.
  3. Uncommitted changes in Web GitHub repository. Was drifting towards measuring productivity.
  4. Amended System Evaluation Questionnaire – it has been structured in categories.
  5. Topped-up printing credits – there should be sufficient credit from-here-on-out.

Dissertation Progress – Day 65

Tasks complete today:

  1. Submitted Ethical Review Application.
  2. Produced rough System Evaluation document – including questions.
  3. Soldered second temperature sensor.

Dissertation Progress – Day 64

Tasks complete today:

  1. Finished Ethics Review – including supporting document.

Dissertation Progress – Day 63

Tasks complete today:

  1. Sourced and printed off written material by Mark Weiser – including his classic paper on ubiquitous computing.
  2. Completed Project Description for Ethics Review Application.
  3. Finished writing functionality for class SystemProcessUtil (incl. internal classes… for the meantime).

Dissertation Progress – Day 62

Tasks complete:

  1. Redesigned and restructured the client application to attempt to start automatically on system boot.
  2. Drawn up sequence diagram in MS Visio to reflect changes in client application structure.
  3. Implemented Thread functionality that delays operation of application to ensure a connection to Eduroam is established.
  4. Wrote the ‘Acknowledgements’ chapter in the Project Report.
  5. Finished Ethical Review Application – including an Evaluation Plan, submitted as a supporting document.

Dissertation Progress – Day 61

Tasks complete today:

  1. Created x2 questionnaire evaluation documents – System Evaluation and Web Application Evaluation.
  2. Finished implementing the main loop for the client application.
  3. Begun researching into executing a .JAR on start-uparticle
  4. Setup RPi 2 to connect to home network. Eduroam has been commented out for the meantime.
  5. Setup RPi 1 + 2 both automatically load LXterminal on boot – Part I
  6. Setup LXterminal to load .JAR using bash shell script on RPi 1 + 2 – Part II. Don’t forget to chmod 755 ‘file-name’ to set permissions.
  7. Sent a library manager an email, to inform them of my progress. I will be deploying the client systems in their office for evaluation purposes.