Struts Adapter Builder

 

In this topic ...

How do I...

Specifying Inputs

Objects this Builder Creates

Use this Builder to access key Struts Java classes from a Factory Model. You might want to do this if you have an existing Struts application that you want to re-write it to take advantage of the Factory's runtime Builder set. This Builder will enable you to reuse much of the original Struts code.

This Builder provides access to a controller-level logic contained in Struts "Actions" and "Form Beans."  The Struts classes this Builder makes available include:

  • Form Bean Classes - Bean classes are specifically used to hold page inputs in a Struts application, with optional validation code

  • Action Classes - Java classes that implement "business actions" in a Struts application

  • Other Java objects - Used by Action classes and stored in HTTP session or request

This Builder will read a Struts configuration file and automatically expose all the actions and form beans present in that file. This Builder does not add any support for the use of Struts tags in pages, so pages have to be built using Factory WebApp Builders.

The Struts Adapter Builder creates a method for each mapped Struts action that can be used to call the action. These methods (with the assistance of a helper LJO) create the appropriate arguments and invoke the action s execute method as if it was being called by the Struts servlet. In addition,  form beans used by the Struts actions can be hooked up to Factory variables, so Builders like Data Page can access these form beans.

Note:  This Builder does not support DynaFormBeans.

Note: In Action and ActionForm classes, there is no support for ActionServlet, MultiPartRequestHandler, DataSource, or MessageResources (these will all be null).

 

How do I...

See this Builder in Action

A sample model illustrating the use of this Builder is included in the Factory. Examine this sample model to see the Struts Adapter Builder in action. This sample includes a comment Builder that describes how the model is constructed and what the Builders are doing within the model.

To access this sample add the "Struts Adapter Builder Sample" Feature Set to a project. Then open the model: .../ WEB-INF/models/struts_Adapter/StrutsBanking.model.

Use Struts Actions

To call a Struts Action, fill in an Action Mapping entry in the Builder, and set the "Factory Action" input to the Factory page or method you want to be called after the Struts action completes.

Each Struts Action will have a corresponding Factory method created that is used to call the Action.  For example, to call a "/login" action and its corresponding "LoginAction" class, you would call the generated "strutsAction_login" method.

Use Struts Beans

To access Form Beans or other Beans that are used in the Struts code, create an entry in the Struts Bean Variables section.  This section is automatically populated by all the Form Beans in the Struts config file, but we can add other Beans manually also.

For example, if you want to access an object that is stored in Session or Request by an Action, we can associate a Factory Variable/LJO with that object.

Perform Struts-style Validation

To use Struts Action Messages, you will need to set the Builder input that specifies the resource bundle containing the messages.  You can then use the "validate" method of Form Beans, and we can display the messages set by Struts Action code.

To use the "validate" method of Form Beans follow these procedures:

  • The Builder generates a strutsValidate_formBeanName method that calls the "validate" method on the Bean and returns a String of any error message(s) returned from the validate method.

  • To use with Data Page, set the "Post Save Action" to this validate method, and set the button that submits the form to the "NextAction" method of the data page.  Also, set the "Full Error Location" input to the location where you want errors displayed.

To display messages from Action classes, the helper class has a getActionMessages method that returns all the action errors/messages. There is also a getActionMessageXml method that returns just the XML of the message text.

 

Specifying Inputs

This Builder takes the inputs described in the table below. For help on inputs common to many or all Builders such as those in the Properties input group, see "Using the Builder Call Editor"

Input Name Description
Name Enter a name for this Builder call. The Designer displays this name in the Builder Call List.

This name will be used as the name of the helper Linked Java Object the Builder generates.

Struts Config File (Optional) Path (relative to this project)  to a copy of an existing Struts configuration struts-config.xml file.

Note: When this input is provided, the Builder UI can use this information to pre-populate other Builder inputs.

Get Config Button Press this button when a Struts Config file is specified above. The Builder will read the file and populate various input pickers with appropriate values drawn from the file.
Message Resource Bundle (Optional) Name of a resource bundle that can be used to provide text for errors and action messages referenced by your Struts action/bean classes.
Action Mappings
Action Path Note: This table can be largely pre-populated from the existing Struts application configuration file is this is specified above.

For each Struts Action Path mapping you want to use in this model, you will need to indicate the corresponding Factory model action. We can specify:

  • Action Class - Name of an existing Struts Action class

  • Form Bean variable -Associated form bean to use with this action

  • Forward Name - Named output result for this action path

  • Factory Action -  Model action you want to map to
Struts Bean Variables
Variables Note: This table can be largely pre-populated from the existing Struts application configuration file is this is specified above.

Use this input to create associations between Struts form beans and Factory variables. Once such an association is established, we can reference a From Bean from other Builders.

For each Variable-to-Form Bean mapping,  you can specify the following:

  • Scope - Of the variable. Choose Session or Request.

  • Class Name - Name of the class to use for this bean

  • Session/Request Attribute Name - Name of the attribute in which this value is stored

  • Method to get variable -Name of method to call to retrieve variable.

 

Objects this Builder Creates

Linked Java Objects

  • <buildername> - LJO that includes helper methods used internally by the Builder

Methods

  • strutsAction_<a> - For each action <a>  specified under the "Action Path" column of the "Action Mappings" input, the Builder will create a method named strutsAction_<a>. Call this method to invoke the associated action.