JBoss.orgCommunity Documentation
In this chapter we'll introduce you to featured graphical editors for specific Struts files such as Struts Configuration files, Tiles files, Struts Validation files and web.xml.
The web.xml file inside the WEB-INF folder is a deployment descriptor file for a Web Application. It describes the servlets and other components and deployment properties that make up your application.
JBoss Tools add the web.xml file to created Struts project automatically and provides a special editor for its editing. See the Visual Web Tools guide that gives a descriptive information on the web.xml editor.
First, let's dwell on the Struts Configuration file editor.
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.
Now, we'll consider every view in more detail.
The Diagram view graphically displays the Web flow of the application defined in the Struts configuration file.
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:
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).
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 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.
Let's consider the tree on the left more closely.
Under the data-sources node you can create a Data Source object that will be configured and made available as a servlet context attribute.
The form-beans node is meant for creating a set of form bean descriptors for this module. Every created element under this node is a JavaBean that implements the org.apache.struts.action.ActionForm class. Use the Properties editor on the right to adjust properties specific to every created form-bean.
The global-exceptions node is intended for registering the handlers for the exceptions that might be thrown by an Action object.
Use the global-forwards node to add, edit or delete a global forwards that represent ActionForward objects available to all Action objects as a return value.
The controller node allows you to configure the controller properties.
Under the resources node you can add, delete, or edit message resources.
Under the plug-ins node you can define a Struts plug-in. Right-click the node, select Create Plug-in and specify the plug-ib Id and ClassName by pointing to the Java class which implements the org.apache.struts.action.PlugIn interface.
In the Source view, you have complete editing control of the underlying XML coding.
When working in Source view, you always have all the following features available:
Content Assist
Open On Selection
File Folding
You can take advantage of code assist.
The editor will also immediately flag any errors.
Finally, you can use the Outline view with the editor to easily navigate through the file.
Find more information about editor features in the editor features chapter.
Here, you'll know how to make use of the special graphical editor for Tiles configuration 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.
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.
To edit the file, simply right click any node and select among the available actions.
The Diagram view allows you to create complex Tiles files in the form of a diagram.
To create new definitions, simply right click anywhere in the diagram.
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.
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
Code assist is available in the Source mode.
Any errors are immediately reported as shown below:
You can also use the Outline view together with the editor's Source mode. It provides an easier navigation through the file.
Providing full support for development Struts applications JBoss Tools comes with a visual validation editor. To open the editor double-click on the validation file or if you don't have it create a new one.
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.
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.
The Constants view let you set constant values for your validation rules.
The validation file can also be viewed in a Tree view.
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.
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.
Here are the validation rules shown in the Source mode.