Struts Design Editor in MyEclipse

Use the Struts Design Editor to lay out the flow of your application. 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.

 

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.

Application flow shown in the Struts 1 designer


Application flow shown in the Struts 2 designer

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:

  • JSPs
  • Actions
  • ActionForwards
  • ActionForms**
  • 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


All available Struts 1 wizards

Outline View
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.


Launching Struts wizards from the Outline view

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.


New Struts action wizard

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.

Struts Designer
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.


Accessing the Struts Designer

    After switching to the Designer, you see a view that looks like the image below.

      Overview of Struts 1 Designer

      2.2 Struts 2

      A typical Struts 2 project consists of the following categories of development artifacts:

      • JSPs
      • Actions
      • Results
      • Packages
      • Struts 2 deployment descriptor: struts.xml

      Struts Designer
      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.

      Editor tabs

      The Flow editor contains a palette of tools for creating various Struts 2 components.

      flow_palette
      Flow designer palette

      Outline View
      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.

      Outline view and context menu

      3. Source View

      The Source editor provides content assist support for Struts elements. Invoke content assist by pressing the CTRL+Space keyboard shortcut.

      Content assist used to add package attributes in a Struts 2 project


      Content assist used to extend packages in a Struts 2 project


      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.
      Pressing CTRL and pointing to a hyperlink

      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.

      Error feedback for empty package name

      Error message for extending an undefined package

      Error message for including a nonexistant configuration file

      Error feedback when the result references an action that is not present in the given namespace


      4. Struts Editor Utilities

      The following images are of the Struts 2 flow designer; however, the same utilities are available for Struts 1.

      4.1 Auto Layout

      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.

      Invoking Auto Layout from the Struts 2 Flow editor

      4.2 View Menu

      The View menu in the editor provides zoom in, zoom out, grid, and snap to geometry options.

      View menu

      4.3 Exporting to Image

      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.

      Exporting diagram to an image