2.2.6. Code Generation for Action, FormBean, Forward and Exception Classes

JBoss Developer Studio comes with a code generation feature. You can generate stub code for Struts Actions, FormBeans, Forwards and Exceptions.

The code generation in JBoss Developer Studio is based on Velocity templates which can be modified for your use. The templates are located at {RedHatDeveloperStudioHome} > 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....

Selecting Generate Java Code

Figure 2.104. 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.

Generate - Step 1

Figure 2.105. Generate - Step 1


Tip:

please be careful not to override your existing files.

When generation is complete, a result window will appear letting you know how many classes were generated:

Generation Finished

Figure 2.106. Generation Finished


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.

Generation For Individual Struts Artifact

Figure 2.107. Generation For Individual Struts Artifact


The same can be done from within the Tree viewer for the editor of the Struts configuration file.

Generation in Struts Config Editor

Figure 2.108. Generation in Struts Config Editor