Struts Tools Reference Guide: Version: 3.0.0.GA
Struts Tools Reference Guide: Version: 3.0.0.GA
Version: 3.0.0.GA
1. Introduction ................................................................................................................. 1
1.1. Key Features of Struts Tools ............................................................................... 1
1.2. Other relevant resources on the topic .................................................................. 2
2. Projects ....................................................................................................................... 3
2.1. Creating a New Struts Project ............................................................................. 3
2.2. Importing an Existing Struts Project with Any Structure .......................................... 8
2.3. Adding Struts Capability to an Existing Web Application ........................................ 9
3. Editors ....................................................................................................................... 17
3.1. Graphical Editor for Struts Configuration Files ..................................................... 17
3.1.1. Diagram View ........................................................................................ 17
3.1.2. Tree View .............................................................................................. 19
3.1.3. Source View .......................................................................................... 20
3.2. Graphical Editor for Tiles Files ........................................................................... 23
3.2.1. Create New Tiles File ............................................................................. 23
3.2.2. Tree View .............................................................................................. 24
3.2.3. Diagram View ........................................................................................ 26
3.2.4. Source ................................................................................................... 28
3.3. Graphical Editor for Struts Validation Files .......................................................... 30
4. Modules ..................................................................................................................... 37
4.1. When Importing a Struts Project ........................................................................ 37
4.2. Editing Modules in an Existing Project ................................................................ 38
4.3. Adding New Modules ........................................................................................ 39
5. Code Generation ........................................................................................................ 41
6. Struts Configuration File Debugger ........................................................................... 45
7. Customizable Page Links Recognizer ....................................................................... 47
8. Struts Project Verification ......................................................................................... 49
9. Relevant Resources Links ......................................................................................... 53
iii
iv
Chapter 1.
Introduction
If you prefer to develop web applications using Struts technology JBoss Tools also meet your
needs. The professional developer toolset provides all necessary editors and wizards for creating
Struts resources that enhances the process of building high-quality web applications.
Note:
Note that JBoss Tools support the Struts 1.1, 1.2.x versions.
In this guide you will learn how to take advantage of Struts support that JBoss Tools provide.
1
Chapter 1. Introduction
2
Chapter 2.
Projects
JBoss Tools provide the following functionality when working with Struts:
• Import (open) existing Struts projects. You can import any project structure
• Import and add Struts capabilities to any existing project created outside Eclipse.
• Select File > New > Project... from the menu bar. Then, select JBoss Tools Web > Struts >
Struts Project in this dialog box. Click Next:
3
Chapter 2. Projects
• On this form, provide the Project Name. You can also select where to create the project or use
the default path.
Tip:
Don't put spaces in project names since some OS could experience problems with
their processing and searching these files.
You can select the KickStart template, then the project created will include a simple Hello World
type application that is ready to run.
4
Creating a New Struts Project
• Next, you register this application with the current servlet container defined for your workspace
(JBoss AS, by default) in order to allow you to test your application more easily while still
developing it. A new entry will be added in the servlet container configuration file to enable
running the application in-place (called null deployment or link deployment). Uncheck the
"Target Server" check box if for some reason you don't want to register your application at
this point.
5
Chapter 2. Projects
• On the next form, you can select the TLD files to include in this project:
6
Creating a New Struts Project
After the project is created, you should have the following project structure (if you used the
KickStart template):
7
Chapter 2. Projects
Tip:
If you want to hide the jar files from Web App Libraries in view, select the down-
pointing arrow in the upper right corner, select Filters..., check the box next to
Name filter patterns (matching names will be hidden), and type *.jar into the field.
Then, click OK.
8
Adding Struts Capability to an Existing Web
Application
2.3. Adding Struts Capability to an Existing Web
Application
Here, we'll consider how to add Struts functionality (Struts libraries, tag libraries and a Struts
configuration file) to any existing Web application project in your Eclipse workspace.
By adding a Struts Nature to your project, you can now edit files using JBoss Tools editors, such
as the Struts configuration editor and the JBoss Tools JSP editor. To take advantage of this just
right-click the project and select JBoss Tools > Add Struts Capabilities from the context menu.
This will start the process of adding all necessary libraries and files to make a Web Struts project
from your one.
9
Chapter 2. Projects
In the wizard you should point to location of your deployment descriptor file web.xml and name
of the project.
10
Adding Struts Capability to an Existing Web
Application
After hitting Next, you will see the following screen. This screen simply means that you need
to add at least one Struts module to your project to make this project a Struts project. Adding a
Struts module means that a new struts-config.xml will be added to your project and registered in
the web.xml file. In addition, all required Struts libraries will be added. To add a Struts module,
select the Add Struts Support button.
11
Chapter 2. Projects
Here you can select what Struts Version, Servlet Class, URL Pattern and TLDs to add to this
project.
12
Adding Struts Capability to an Existing Web
Application
When done, you will see the default Struts module configuration information. See how to Edit
Struts modules.
13
Chapter 2. Projects
On the last screen you can set the different folders for your project as well as register this
application with a servlet container. If you want the libraries (.jar files) will be automatically added
to your project, click on the checkbox Add Libraries.
14
Adding Struts Capability to an Existing Web
Application
When done, you can open end edit the struts-config.xml file using usefull Struts configuration file
editor provided by JBDS. (The Struts configuration is shown below in the Tree viewer).
15
Chapter 2. Projects
16
Chapter 3.
Editors
In this chapter we'll introduce you to featured graphical editors for specific Struts files such as
Struts Configuration files, Tiles files and Struts Validation files.
This editor has three views with different representation of struts-config.xml: Diagram, Tree and
Source. The views can be selected via the tabs at the bottom of the editor. Any changes made in
one view are immediately visible when you switch to any other view.
The Diagram view allows to edit navigation in your Struts application. Just by right-clicking
anywhere on the diagram, you can use a context menu to create the building blocks of a Struts
application:
17
Chapter 3. Editors
• Actions
• Global forwards
• Global exceptions
• JSP Pages
Along the upper-left side of the editor is a stack of seven icons for changing the behavior of the
cursor in the diagram.
The first icon switches to the default regular selection cursor, the second to the marquee selection
cursor and the third to the new connection cursor. The last four icons switch the cursor to an insert
cursor for each type of Struts build block listed above (and in the order listed).
18
Tree View
For instance, clicking on the first of these four icons (the one with the gears) will switch the cursor to
insert actions. Clicking anywhere in the diagram with this cursor has the same effect as right-click
and selecting Add > Action... from the context menu with the regular cursor active. It's just more
efficient to use this cursor if you're adding more than one action at once.
The Tree view represents the different elements of the Struts application that are organized into
functional categories on the left-hand side and a form for editing the properties of currently selected
items on the right-hand side.
You can also right-click on any node in the category tree and perform appropriate operations
through a context menu. For instance, by right-clicking on the action-mappings category node,
you can add new actions to the application.
19
Chapter 3. Editors
In the Source view, you have complete editing control of the underlying XML coding.
20
Source View
When working in Source view, you always have all the following features available:
• Content Assist
• Open On Selection
• File Folding
21
Chapter 3. Editors
Finally, you can use the Outline view with the editor to easily navigate through the file.
22
Graphical Editor for Tiles Files
The editor has three main views: Tree, Diagram and Source. The views can be selected via the
tabs at the bottom of the editor. Any changes made in one view are immediately visible when you
switch to any other view.
Before we consider each view of the editor, let's look at the way of creating new Tiles files.
To create new Tiles files, right click any folder and select New > Tiles File.
23
Chapter 3. Editors
The Tree view represents the different elements of the Tiles file that are organized into functional
categories on the left-hand side and a form for editing the properties of currently selected items
on the right-hand side.
24
Tree View
To edit the file, simply right click any node and select among the available actions.
25
Chapter 3. Editors
The Diagram view allows you to create complex Tiles files in the form of a diagram.
26
Diagram View
27
Chapter 3. Editors
You can also use the Diagram toolbar to make editing easier.
It contains four icons for changing the cursor state. The first one is the default cursor state for
selecting existing nodes. The second icon is marquee selector. The third is used for creating new
connections and the last one is for adding definition template to the content.
3.2.4. Source
The other view of the Tiles editor is the Source view that gives you full control over the source.
Any changes here will immediately appear in other modes when you switch to them.
When working in Source view, you always have all following features available:
• Content Assist
• Open On Selection
28
Source
29
Chapter 3. Editors
You can also use the Outline view together with the editor's Source mode. It provides an easier
navigation through the file.
To create a new validation file, right click any folder in Project Explorer and select File > New >
Other... from the context menu and then JBoss Tools Web > Struts > Validation File.
30
Graphical Editor for Struts Validation Files
The validation editor works with five modes: Formsets, Validators, Constants and standard Tree
and Source that you can easily switch over using tabs at the bottom of the editor.
The Formsets view shows forms and their elements on the left side and the dialogue for defining
their validation rules on the right side.
31
Chapter 3. Editors
The Constants view let you set constant values for your validation rules.
32
Graphical Editor for Struts Validation Files
33
Chapter 3. Editors
At any point you have full control over the source by switching to the Source view. Any editing in
this view will immediately be available in other views of the editor.
34
Graphical Editor for Struts Validation Files
You can also open your own custom or Struts-standard validation-rules.xml file.
The Validators view shows the validation rules for a selected validator. You can of course add
your own rules.
35
Chapter 3. Editors
36
Chapter 4.
Modules
JBoss Tools support working with Struts projects that have multiple modules. You can easily do
the following:
37
Chapter 4. Modules
You will see the same screen as above where you will be able to select a module and edit its
details.
38
Adding New Modules
You will see the screen below. You can specify a new module name and also add the new Struts
configuration file to web.xml file.
39
40
Chapter 5.
Code Generation
JBoss Tools comes with a code generation feature. You can generate stub code for Struts Actions,
FormBeans, Forwards and Exceptions.
The code generation that JBoss tooling provides is based on Velocity templates which can
be modified for your use. The templates are located at {JBossStudioHome} > templates >
codegeneration.
There are a number of ways to invoke code generation. One is simply right-clicking the Struts
diagram and selecting Generate Java Code....
On this screen you can select for which elements to generate code. If you select Next you will be
able to specify more options for each of the categories you selected.
41
Chapter 5. Code Generation
Tip:
When generation is complete, a result window will appear letting you know how many classes
were generated:
42
You don't always have to generate code for all elements at once. You can invoke generation
for just an individual Struts artifact as well. Right-click an element on the diagram of the Struts
configuration file and select Generate Java Code... from the context menu.
The same can be done from within the Tree viewer for the editor of the Struts configuration file.
43
44
Chapter 6.
45
46
Chapter 7.
47
48
Chapter 8.
To configure Struts project verification select Window > Preferences from the menu bar, select
JBoss Tools > Web > Verification from the Preferences dialog box and then expand the Struts
Rules node.
Suppose you are working in the Source viewer for a Struts configuration file as shown below:
49
Chapter 8. Struts Project Ver...
While typing a class name or entering it from the graphical editor, you might make a minor typo (like
"sample.GreetingAction1" instead of "sample.GreetingAction" ). After saving the file, verification
checks to make sure everything is correct and finds the error below:
Notice that the Package Explorer View shows a marked folder and a marked file where the error is.
You can place the cursor over the line with the error to view a detailed error message:
The verification also checks to make sure you have specified the correct JSP page for the forward:
50
Figure 8.5. JSP Page Verification
Once you place the cursor over the line, you can see the error message:
You can always invoke the verification by switching to the Diagram viewer, right-clicking and
selecting Verify from the context menu:
51
52
Chapter 9.
In summary, this reference should help you to get familiar with those parts of JBoss Tools which are
meant for development with Struts technology. If you've carefully gone through the document, you
should know now how to create/import Struts project or enable Struts capabilities for an existing
web project as well as organize and edit all necessary staff for your Struts application using a set
of views and editors provided by JBoss Tools.
If you'd like to contribute your feedback is always appreciated. You can leave your questions and
suggestions on our Forum [http://www.jboss.com/index.html?module=bb&op=viewforum&f=201].
53
54