Struts subtasks

struts

The Struts subtasks include tasks to generate Forms from entity beans, and to generate struts-config.xml from Form and Action classes.

<strutsform />

The <strutsform /> subtask is a subtask of the <ejbdoclet /> task. It processes all entity beans and generates struts form beans.

Form beans include getter and setter methods and also convenient bulk data setting methods (in form: <DataObjectType> getData() to return data object with only form fields set, and <DataObjectType> getData(<DataObjectType>) to merge form fields with actual EJB data)

Several forms can be defined for a single EJB, with different sets of properties. validate method of form beans shall be overriden with something more useful than default struts validation method.

PK fields are included by default, but can be excluded if necessary.

Parameters

Attribute Description Required
destdir Base destination directory for the generated source code. No, default is destdir parameter of ejbdoclet task
pattern The pattern by which the form bean classes are named. {0} designates the EJB name, {1} form bean name No, default is {0}{1}Form.

<strutsconfigxml />

The <strutsconfigxml /> subtask is a subtask of the <webdoclet /> task. It parses the source directories for Action and Form classes that contain @struts: tags and generates a struts-config.xml based on that data. It also relies on merging for additional global config options.

Parameters

Attribute Description Required
xmlencoding The encoding of the struts-config.xml file. No, default is "UTF-8"
destdir Destination directory for the struts-config file. No, default is destdir parameter of webdoclet task
mergedir Merge directory where strutsconfig looks for files to be merged with generated files. No, required, if the merge feature used
validateXml Validates the generated xml file according to the DTD file contained inside xdoclet.jar. Please note that the current support for Struts 1.1 beta is not complete. You have to put validateXml to false if you use Struts 1.1 specific features (for example declarative exceptions). No, default is false

Merge Points

Merge File Name Description Required
struts-forms.xml The file where additional forms are defined. No
global-forwards.xml The file where the global forwards are defined. No
global-exceptions.xml The file where the global exceptions are defined. No
struts-actions.xml The file where additional actions are defined. No

Class level Tags

@struts:action

Defines the action class and its attributes.

Parameter Usage
path: String The Application-relative path of the submitted request,
starting with a "/" character, and without the
filename extension if extension mapping is used.
NOTE: Do *not* include a period in your path name,
because it will look like a filename extension and
cause your Action to not be located.
[name]: String Name of the form bean, if any, that is associated with this action.
[attribute]: String Name of the request-scope or session-scope attribute
under which our form bean is accessed, if it is other
than the bean's specified "name". Optional if
"name" is specified, else not allowed.
[prefix]: String Prefix used to match request parameter names to form bean
property names, if any. Optional if "name" is specified,
else not allowed.
[suffix]: String Suffix used to match request parameter names to form bean
property names, if any. Optional if "name" is specified,
else not allowed.
[scope]: "request" | "session" Identifier of the scope ("request" or "session") within
which our form bean is accessed, if any. Optional if
"name" is specified, else not allowed.
[input]: String Application-relative path of the input form to which
control should be returned if a validation error is
encountered. Required if "name" is specified and the
input bean returns validation errors. Optional if "name"
is specified and the input bean does not return validation
errors. Not allowed if "name" is not specified.
[validate]: "true" | "false" Set to "true" if the validate() method of the form bean
should be called prior to calling this action, or set to
"false" if you do not want validation performed.
[parameter]: String General purpose configuration parameter that can be used
to pass extra information to the Action selected by this
mapping.

@struts:action-forward

Defines local forwards for a Struts action class.

Parameter Usage
name: String Unique identifier of this forward, used to reference it
in application action classes.
path: String The application-relative or context-relative path of
the mapped resource (determined by the selected value
for the "contextRelative" attribute).
[redirect]: String Set to "true" if sendRedirect() should be used to forward
to this resource, or "false" in order to use
RequestDispatcher.forward() instead.
[className]: String Implementation subclass of the standard configuration
bean, if you do not want to use the standard value.
[org.apache.struts.action.ActionForward]
[contextRelative]: String Set to "true" if the path should be considered relative
to the entire web application, rather than prefixed with
the sub-application prefix, if it starts with a "/".

@struts:action-exception

Defines a mapping of an exception that may occur during Action delegation and should be handled by the ActionServlet. Struts 1.1 only.

Parameter Usage
[className]: String Implementation subclass of the standard configuration bean, if you do not want to use the standard value. [org.apache.struts.config.ExceptionConfig]
[handler]: String Fully qualified Java class name of the exception handler which should handle this exception. [org.apache.struts.action.ExceptionHandler]
[key]: String Message resources key specifying the error message associated with this exception.
[path]: String The application-relative path of the resource to forward to if this exception occurs.
[scope]: "request" | "session" Identifier of the scope ("request" or "session") within which the resulting ActionError will be made accessible.
[type]: String Fully qualified Java class name of the exception that is to be handled.

@struts:form

Defines a form bean and its attributes.

Parameter Usage Required
[name]: String Define a unique name for the form. Yes.
[extends]: String Define which class the generated form must extend. No.
[implements]: String Define which class the generated form must implement. No.
[include-pk]: "true" | "false" Whether to include pk field in form. Default is true. If set to false, individual pk fields can still be included. No.
[include-all]: "true" | "false" Whether to include all persistent fields in form. Default is false. No.

Method level Tags

@struts:form-field

Parameter Usage Required
[form-name]: String to include this property in specified form. Yes.