Struts Design Editor in MyEclipse
1. Struts Projects
When beginning a Struts project, it's generally useful to lay out the flow of your application so the development team has a better idea how the pieces fit together. The easiest way to stub out the flow is to graphically create it using the Struts editor's graphical design mode. The Struts editor provides a palette of drag-and-drop tools that enable you to begin building your application by quickly replicating the page flow from your design mockups.
MyEclipse supports both Struts 1 and 2. While both have graphical flow design capabilities, the flow design varies between the two versions. Below are examples of the flow of an example login application in both Struts 1 and Struts 2.
2. Components of a Struts Project
Struts 1 and 2 projects are similar, but not entirely the same. The following sections describe each.
2.1 Struts 1
A typical Struts 1 project consists of the following categories of development artifacts:
- Struts 1 deployment descriptor: struts-config.xml
ActionForwards are <forward> entries in the struts-config.xml file defining the path an action takes when it has completed. We are not referring to custom implementations of the ActionForward class, although, for the advanced user, these are possible and supported by the tools. ActionForms can be replaced by the use of DynaForms if you don't want to create concrete ActionForm implementations to wrap page values.
In MyEclipse, creating any or all of these components (except the struts-config.xml file) can be done via three different methods:
New File Wizard
Select File>New>Other from the menu, expand MyEclipse>Web-Struts>Struts 1.x, and choose a Struts wizard
Use the custom Outline view, available when displaying the Struts editor's Source window is active. From the Outline view, right-click any root level node to activate a wizard to create new components of that type, or to edit existing ones.
The wizards prompt you for all values that the selected Struts component supports. Some of these wizards are more complex than others. For example, in the Struts Action wizard shown below, you can see comprehensive coverage of the features supported by a Struts Action.
It is worth noting from this screenshot that some actions are a series of related wizards that allow you to create an entire flow. The wizards are linked together to seamlessly reuse common values and minimize manual re-entry.
The Struts editor's design page is a very convenient way of creating Struts artifacts. The Designer is accessed by opening the struts-config.xml file. Use the tabs at the bottom of the editor to switch between Design and Source modes.
After switching to the Designer, you see a view that looks like the image below.
2.2 Struts 2
A typical Struts 2 project consists of the following categories of development artifacts:
- Struts 2 deployment descriptor: struts.xml
Create Struts 2 artifacts using the graphical Flow editor. By default, Flow editor is active the first time you open the file. For all the subsequent invocations, the last open editor is active. If the Flow editor is not active, activate it by clicking the Flow tab.
The Flow editor contains a palette of tools for creating various Struts 2 components.
The Outline view in the Struts 2 editor shows you a tree view of your flow. It allows you to add/delete/edit elements directly from the outline. Right-click an element to perform multiple actions on your flow.
3. Source View
The Source editor provides content assist support for Struts elements. Invoke content assist by pressing the CTRL+Space keyboard shortcut.
The editor provides support for detecting hyperlinks. Activate hyperlink detection by placing the mouse over a hyperlink and pressing the CTRL key. Clicking the hyperlink will open the associated document in the target editor. The images below show the usage of Hyperlink detection in the Source editor.
Press CTRL+SHIFT+F in the Source editor to auto-format the Struts configuration file. The Struts editor provides support for Struts validations. The editor validates as you type in the Source editor and continues providing feedback in the form of error messages that help you correct the errors immediately.
Note: The examples below are for Struts 2 validation.
The following images are of the Struts 2 flow designer; however, the same utilities are available for Struts 1.
The MyEclipse Struts editor provides auto layout support. To auto-layout a Struts 2 diagram, right-click the Flow editor canvas, and select Auto Layout from the menu. When using Struts 1, select View>Auto Layout from the main menu.
The auto-layout operation takes care of laying out the elements in the diagram. It also performs smart routing of connections.
The View menu in the editor provides zoom in, zoom out, grid, and snap to geometry options.
The MyEclipse Struts editor provides support for exporting the active diagram to .jpg and .png formats. To export to an image, right-click the Flow (or Design) editor canvas, and select Export Image from the menu.