Struts Support - UI Specification
Author: Petr Pisl
$Revision: 1.15 $
$Date: 2005/08/31 16:56:31 $
Topics:
Extending a web project with Struts includes
copying of Struts JAR files and configuration files, changing deployment
descriptor and set up the Struts framework to ready for development.
There are two ways how to add the Struts into a web projects:
-
During creation of a new Web Application. The user is able to add
Struts support neither during creating new Web Application with
Existing Sources nor creating new Web Application with existing Ant
Script.
- When a web project already exist.
Scenario 1 - Creating new Web Application with Struts support:
- Choose New Project -> Web -> Web Application
- Name and Location Panel - without changes
- Adding Capabilities - choose the Struts 1.2.7
- Configure the Struts support in the Struts support panel
- Finish
Scenario 2 - Adding Struts support into already existing Web Application
- Choose the Web Application in the Project view -> go to the Project Properties
-
Choose the Frameworks node. See
here.
-
Click on Add button and choose the Struts framework from the
dialog.
-
The Struts support panel
is displayed in the customizer.
Figure: Shows default value for adding Struts capabilities in new Web Application wizard
+-------------------------------------------------------------------+
| |
| Action Servlet Name: |_action_____________________________| |
| Action URL Pattern: |_*.do_____________________________v_| |
| |
| Application Resource: |_mywebapp.struts.MessageResources___| |
| |
| [ ] Add Struts TLDs |
| |
+-------------------------------------------------------------------+
Components:
-
Action Servlet Name - name of the Struts action servlet name.
Default value: action (which is not editable).
-
Action URL Pattern - how the struts action servlet will be mapped.
Editable list box with predefined value *.do and /do/*. Default value:
*.do
-
Application Resource - where the default application resources
file should be located. Default file:
mywebapp.struts.MessageResources.properties. The first package is the
name of the new Web Application (lower case only).
-
Add Struts TLDs - whether user want to put TLD files of the
Struts tag libraries under /WEB-INF/ folder. Default value: false
Error Conditions:
-
Configuration File, Action Servlet Name, Action URL Pattern and
Application Resource must be entered.
-
Action URL Pattern must be valid non-root servlet mapping (*.suffix, or /prefix/prefix/*).
Dot and star are restricted characters (start - only 1 occurence, dot - at most 1 occurence in *.suffix).
The panel for the customizer is almost the same as the
panel
for new Web Application Wizard, but is disabled. User is not able to change anything from the customizer.
Figure: Panel, which is displayed in the Project Customizer.
+--------------------------------------------------------------------+
| |
| Action Servlet Name: |_action______________________________| |
| Action URL Pattern: |_*.do______________________________v_| |
| |
| Application Resource: |_mywebapp.struts.MessageResources____| |
| |
+--------------------------------------------------------------------+
Components:
- All panel's controls are read-only.
This dialog will not be implemented in NetBeans 5.0.
Figure: Show step wizard for creating new Struts
configuration file and module
+---------------------------------------------------------------------------------+
| New Struts Configuration File |
+---------------------------------------------------------------------------------+
| Name and Location |
| ------------------------------------------------------------------------------- |
| |
| File Name: |_struts-configX.xml _____________________________| |
| Struts Module:|_______________________________________________v_| |
| |
| Project: |_WebApplicationName _____________________________| |
| Folder: |_web/WEB-INF ____________________________________| [ Browse... ] |
| Created File: |_projectpath/web/WEB-INF/struts-configX.xml____________________| |
| |
| |
| |
| [ Back ] Next> [[ Finish ]] [ Cancel ] [ Help ] |
+---------------------------------------------------------------------------------+
Components:
-
File Name - default value is struts-configX.xml, where the X is
number of already existing configuration files with the name struts-config.xml.
-
Struts Module - the editable combobox with all defined Struts Modules in the
deployment descriptor. The default value is default, which means, that the
created file will be written for the default Struts Module. The default Struts Module
doesn't have name. If user enter new name of the module, than new Struts Module is
created.
-
Folder - the Browse button opens the dialog, which offers
only folders inside the working project and the Web Pages folder is as the root.
- Buttons - Next button is disabled and Finish button is selected.
Error Conditions:
- The Created File must be inside the project and doesn't have to exist.
The wizards generate new Form Bean Class and create appropriate form-bean element
in the struts configuration file.
Figure: Shows the New FormBean Wizard panel
+-----------------------------------------------------------------------------------+
| New FormBean Class |
+-----------------------------------------------------------------------------------+
| Name and Location |
| --------------------------------------------------------------------------------- |
| |
| Class Name: |_FormBean_______________________________________________________| |
| |
| Project: |_UserApplication________________________________________________| |
| Location: |_Source Packages _____________________________________________v_| |
| Package: |______________________________________________________________v_| |
| Created File: |_/UserApplication/src/java/XX.java______________________________| |
| |
| --------------------------------------------------------------------------------- |
| |
| Superclass: |_org.apache.struts.action.ActionForm__________________________v_| |
| Configuration File: |_/WEB-INF/struts-config.xml ___________________________v_| |
| |
| |
| [ Back ] [ Next> ] [[ Finish ]] [ Cancel ] [ Help ] |
+-----------------------------------------------------------------------------------+
Components:
-
Upper panel is standard Java panel (incl. warning messages).
-
Superclass is editable combobox where are these values:
- org.apache.struts.action.ActionForm - the default value,
- org.apache.struts.validator.ValidatorForm,
- org.apache.struts.validator.ValidatorActionForm.
Last entered value is stored per project.
-
Configuration File - Struts configuration file, where the new FormBean
will be defined. This listbox contains all Struts configuration files in the working project.
- Next - disabled
- Finish - default value
Error Conditions:
- Configuration File - must be selected.
The wizard creates new Action class and creates action element in the Struts configuration
file.
Figure: Shows step wizard for creating new Action - step 1 - Name and Location
+-----------------------------------------------------------------------------------+
| New Action |
+-----------------------------------------------------------------------------------+
| Name and Location |
| --------------------------------------------------------------------------------- |
| |
| Class Name: |________________________________________________________________| |
| |
| Project: |_UserApplication________________________________________________| |
| Location: |_Source Packages _____________________________________________v_| |
| Package: |______________________________________________________________v_| |
| Created File: |_/UserApplication/src/java/XX.java______________________________| |
|-----------------------------------------------------------------------------------|
| |
| Superclass: |_org.apache.struts.action.Action________________________v_| |
| Configuration File: |_/WEB-INF/struts-config.xml ____________________________v_| |
| Action Path: |___________________________________________________________| |
| |
| |
| [ Back ] [[ Next> ]] [ Finish ] [ Cancel ] [ Help ] |
+-----------------------------------------------------------------------------------+
Components:
-
Upper panel is standard Java panel (incl. warning messages).
-
Action Path - the action path. The path must be unique in the configuration file.
It's the context relative path without the extension (.do for example).
Usually it's like /myAction.
-
Superclass - editable combobox, with these values:
- org.apache.struts.action.Action - default value
- org.apache.struts.actions.DispatchAction
- org.apache.struts.actions.LookupDispatchAction
- org.apache.struts.actions.MappingDispatchAction
Last entered value is stored per project.
-
Buttons - the Next button is the default one. Finish button is disabled. Is not possible
finish the wizard in this step.
Error Conditions:
- Configuration File - must be selected.
- Action Path - must be entered. Must be unique in the configuration file.
- Action Path - should not contain URL pattern (.do or /do/). Warn user that it should be removed.
- Superclass - should be org.apache.struts.action.Action or its subclass.
In this step user can specify the FormBean or attribute, which is used in the action and
parameter for the action. Everything is optional and doesn't have to be
entered. If user want to filled a form, than the form must exist. The
same for Input Resource/Action.
Figure: Show step wizard for creating new Action - Form and Parameter
+-----------------------------------------------------------------------------------+
| New Action |
+-----------------------------------------------------------------------------------+
| Form, Attribute |
| --------------------------------------------------------------------------------- |
| [x] Use FormBean |
| Form Name: |_______________________________________v_| |
| (o) Input Resource: |_________________________________________| [ Browse... ] |
| ( ) Input Action: |_______________________________________v_| |
| |
| Scope: (o) Session ( ) Request |
| Attribute: |_________________________________________| |
| |
| [x] Validate Form Bean |
| |
| Parameter: |_________________________________________| |
| Specific label (Action dependent) |
| |
| [ Back ] [[ Next> ]] [ Finish ] [ Cancel ] [ Help ] |
+-----------------------------------------------------------------------------------+
Components:
-
Form Name - not editable combobox offering all FormBeans declared in the
Struts configuration file, which is entered in the
previous panel.
-
Input Resource - the Browse... button opens an file browse dialog, where
the Web Pages are the root.
-
Input Action - not editable combobox with all actions from the Struts
configuration file, which is entered in the
previous panel.
-
Specific label (Action dependent) - label depends on selected Superclass
in previous panel:
- Action - Specific label is empty
- DispatchAction - "URL name which contains called method on action"
- LookupDispatchAction - "URL name which contains key of called method on action"
- MappingDispatchAction - "Name of called method on action"
- The selected button is Next.
-
The Finish button is enabled.
Error Conditions:
- Form Name - must exist.
-
Input Resource or Input Action - must be entered.
-
Parameter - must be entered if Superclass from previous panel is DispatchAction,
LookupDispatchAction or MappingDispatchAction.
This dialog will not be implemented in NetBeans 5.0.
In this step user can specify the forwards and the exceptions for the action.
Figure: Show step wizard for creating new Action - Forwards and Exceptions
+------------------------------------------------------------------------------------+
| New Action |
+------------------------------------------------------------------------------------+
| Forwards and Exceptions |
| ---------------------------------------------------------------------------------- |
| |
| Forwards: |_________Name_________|________Path __________|_Redirect_| |
| | success | /ok.jsp | [ ] | [ Add... ] |
| | error | /error.jsp | [x] | [ Remove ] |
| | | | | [ Edit...] |
| | | | | |
| +--------------------------------------------------------+| |
| |
| Exceptions: |________Type________|_______Key ______|_______Path_______| |
| | java.io.IOException| error.exception |/exception.jsp | [ Add... ] |
| | | | | [ Remove ] |
| | | | | [ Edit...] |
| | | | | |
| +--------------------------------------------------------+| |
| |
| |
| [ Back ] Next> [[ Finish ]] [ Cancel ] [ Help ] |
+------------------------------------------------------------------------------------+
Components:
-
Forwards - table with forward definitions for the action. The buttons Add... and
Edit... open dialog for adding/editing forwards.
-
Exceptions - table with exception definitions for the action. The buttons
Add... and Edit... open dialog for adding/editing exceptions.
The Dialog is accessible through the context menu in editor for Struts
configuration file. Includes elements with definition of a FormBean. User
can define two types of the FormBean. The FormBean representing with and
existing class and the dynamic type.
Figure: Shows dialog for entering new FormBean
element to the struts configuration file
+----------------------------------------------------------------------------------------+
| Add FormBean |
+----------------------------------------------------------------------------------------+
| |
| Form Name: |_________________________________________________| |
| (o) FormBean Class: |_________________________________________________| [ Browse... ] |
| ( ) Dynamic: |_org.apache.struts.action.DynamicActionForm_v____| |
| |
| [[ Add ]] [ Cancel ] [ Help ] |
+----------------------------------------------------------------------------------------+
Components:
-
FormBean Class - the button Browse opens dialog for finding the class.
Dynamic - editable combobox, which offers these values:
- org.apache.struts.action.DynaActionForm - the default value,
- org.apache.struts.validator.DynaValidatorForm,
- org.apache.struts.validator.DynaValidatorActionForm.
-
Properties - defined properties for dynamic bean. When user press
the Add button, then new line is added to the table, where user can enter the appropriate
texts.
The columns:
- Name - name of the property.
- Type - type of the property. The button opens dialog for finding class.
- Init Value - init value for the property, if the property is not array.
- Array - user mark, whether the property is array.
- Size - size of the array
If the property is an array, then the init value is not valid. If the property is not
an array, then Size is not valid.
Error Conditions:
- Form Name - must be entered and must be unique in configuration file.
-
FormBean Class or Dynamic - must be entered.
The dialog is composed from panels which are identical with panels in the New Action Wizard
(
FormBean, Attribute ,
Forwards and Exceptions ).
Figure: Shows dialog for entering Forward or Include Action
+-----------------------------------------------------------------------------------+
| Add Action |
+-----------------------------------------------------------------------------------+
| Action Class: |_________________________________________| [ Browse... ] |
| Action Path: |/________________________________________| |
| |
| [x] Use FormBean |
| Form Name: |_______________________________________v_| |
| (o) Input Resource: |/________________________________________| [ Browse... ] |
| ( ) Input Action: |_______________________________________v_| |
| |
| Scope: (o) Session ( ) Request |
| Attribute: |_________________________________________| |
| |
| [x] Validate Form Bean |
| |
| Parameter: |__________________________________________________| |
| Specific label (Action dependent) |
| |
| [[ Add ]] [ Cancel ] [ Help ] |
+-----------------------------------------------------------------------------------+
Components:
-
Action Class - full qualified name of an action class. The Brose...
button opens dialog for finding the class. Last entered value is stored per project.
-
Specific label (Action dependent) - label depends on superclass of selected Action Class:
- Action, anything else - Specific label is empty
- DispatchAction - "URL name which contains called method on action"
- LookupDispatchAction - "URL name which contains key of called method on action"
- MappingDispatchAction - "Name of called method on action"
-
Other components are described in FormBean, Attribute and
Forwards and Exceptions
Error Conditions:
- Action Class - must be entered. Should be org.apache.struts.action.Action or its subclass.
- Action Path - must be entered. Must be unique in the configuration file.
- Action Path - should not contain URL pattern (.do or /do/). Warn user that it should be removed.
- Form Name - must exist.
-
Input Resource or Input Action - must be entered.
-
Parameter - must be entered if Action Class is inherited from DispatchAction,
LookupDispatchAction or MappingDispatchAction.
Figure: Shows dialog for entering Forward or Include Action
+-----------------------------------------------------------------------+
| Add Forward/Include Action |
+-----------------------------------------------------------------------+
| |
| Action Path: |/_____________________________| |
| Action Type: |
| (o) Forward Action |
| ( ) Include Action |
| Call: |
| (o) Resource File: |______________________________| [ Browse... ] |
| ( ) Action |____________________________v_| |
| |
| [[ Add ]] [ Cancel ] [ Help ] |
+-----------------------------------------------------------------------+
Components:
-
Action Type - the type of the action.
-
Call - Resource File - the Browse... button opens an file browse dialog, where
the Web Pages are the root.
-
Call - Action - not editable combobox with all actions from the Struts
configuration file, which is entered in the
previous panel.
Error Conditions:
- Action Path - must be entered. Must be unique in the configuration file.
- Action Path - should not contain URL pattern (.do or /do/). Warn user that it should be removed.
- Call - Resource File or Call - Action - must be entered.
This dialog is accessible from the contexmenu overt the Struts configuration
file. Adds the global or action forward.
Figure: Shows dialog for defining new Forward in the Struts configuration file.
+----------------------------------------------------------------+
| Add Forward |
+----------------------------------------------------------------+
| |
| Forward Name: |__________________________| |
| Forward To: |
| (o) Resource File:|/_________________________| [ Browse... ] |
| ( ) Action: |________________________v_| |
| [ ] Redirect |
| |
| Location: |
| (o) Global |
| ( ) Action: |_________________________v_| |
| |
| |
| [ Add ] [ Cancel ] [ Help ] |
+----------------------------------------------------------------+
Components:
- Forward Name - name of the forward. It's blank by default.
-
Forward To Resource File - the Browse button opens Browse dialog, which offer
Web Pages as root.
-
Forward To Action - editable combobox, which offers all actions defined
in the struts configuration file.
-
Location Action - non-editable listbox, which offers all actions defined in the
struts configuration file.
Error Conditions:
- Forward Name - must be unique in the Struts module.
- Forward To - Resource File or Forward To - Action must be entered.
Figure: Show step wizard for creating new Forward
+----------------------------------------------------------------------------+
| Add Exception |
+----------------------------------------------------------------------------+
| |
| Bundle Key: |_Key_______________________________v_| |
| Exception Key: |___________________________________v_| |
| Exception Type: |_____________________________________| [ Browse... ] |
| Call: |
| (o) Resource File: |_____________________________________| [ Browse... ] |
| ( ) Action: |___________________________________v_| |
| |
| Scope: (o) Session ( ) Request |
| |
| Location: |
| (o) Global |
| ( ) Action: |___________________________________v_| |
| |
| |
| |
| [ Back ] [ Next> ] [[ Finish ]] [ Cancel ] [ Help ] |
+----------------------------------------------------------------------------+
Components:
-
Bundle Key - the message resources bundle associated with this
handler. The default attribute is the value specified by the string
constant declared at Globals.MESSAGES_KEY. The other values are taken
from the Configuration File.
-
Exception Key - a key from the resource file, which is defined with the
Bundle value. The Browse button open dialog, which display all keys
from the resource file.
-
Exception type - type of the exception which is caught.
The Browse... button open dialog for finding the class.
-
Call - Resource File - the Browse... button opens an file browse dialog, where
the Web Pages are the root.
-
Call - Action - not editable combobox with all actions from the Struts
configuration file, which is entered in the
previous panel.
-
Location - Action - the non-editable listbox is enabled only when user chooses Action
Exception. The listbox contains all actions, which are in the configuration file.
Error Conditions:
-
Exception Key - must be selected, from the resources file, which is defined
in the Config file.
- Exception type - must be defined
- Call - Resource File or Call - Action must be entered.
TBD
When user uses code completion for the Struts tags and their
attributes, there is shown help in Javadoc popup window. Like for html
tags.
When user edits a jsp file and uses Struts tags, it's very useful to
provide hyperlink for faster navigation between the jsp files and
Struts configuration files, application resources etc.
| Tag |
Attribute |
Where |
| bean: message |
key |
definition mykey in the application resources file |
| html:form |
action |
definition myaction in the Struts configuration file |
| html:link |
module |
to the Struts configuration file, where is the module defined |
|
path |
It the value is a resource from
the web application, then open the jsp, html or servlet. If the value
is an action, open the the Struts configuration file, where the action
is defined.
|
The javadoc fro the Struts classes must be shown in JavaDoc popup
window in the java editor.
The contextual menu is taken from the XML Editor, but the dialogs
for adding elements should be accessible through this menu and there
should be action for validation of the file.
Contextual Menu:
Struts >
Select in >
Cut CTRL-X
Copy CTRL-C
Paste CTRL-V
Reformat Code CTRL-SHIF-F
Check XML ALT-F9
Validate XML ALT-SHIFT-F9
Tools
Contextual Struts SubMenu:
Add FormBean
Add Action
Add Forward/Include Action
Add Forward
Add Exception
---------------------------
New FormBean
New Action
---------------------------
Validate
TBD
The Struts configuration file can be large and it's useful to have way
how to quickly navigate between a definition of an element and using
the elements.
| Element |
Attribute |
Where |
| form-beans |
type |
the appropriate java file |
| form-bean |
type |
the appropriate java file |
|
className |
the appropriate java file |
|
action |
definition myaction in the Struts configuration file |
| global-exceptions |
className |
the appropriate java file |
|
handler |
the appropriate java file |
|
key |
key in the application resource file |
|
path |
into the resource that will complete the request/response |
|
type |
the appropriate java file |
| exception |
type |
the appropriate java file |
| global-forwards |
type |
the appropriate java file |
| forward |
className |
the appropriate java file |
|
path |
relative path to the resource |
| action-mappings |
type |
the appropriate java file |
| action |
className |
the appropriate java file |
|
forward |
relative path to the resources |
|
include |
relative path to the resources |
|
input |
relative path to the resources |
|
name |
the row with the definition of form-bean in the Struts configuration file |
|
path |
relative path to the resources |
|
type |
the appropriate java file |
| message-resources |
className |
the appropriate java file |
|
factory |
the appropriate java file |
|
parameter |
the appropriate resource file |
Validation action for Struts Configuration File validates the value of
the elements. It saves user to create errors in the configuration file.
What should be checked:
TBD
+-----------------------------------------------------+
| Navigator |
+-----------------------------------------------------+
| [A] Action mappings |
| + [a] Action mapping 1 |
| + [a] Action mapping 2 |
| [D] Data Sources |
| + [d] Data source |
| [F] Form beans |
| + [f] Form Bean 1 |
| + [f] Form Bean 2 |
| [E] Global Exceptions |
| + [e] Global Exception 1 |
| + [e] Global Exception 2 |
| [R] Global Forwards |
| + [r] Global Forward 1 |
| + [r] Global Forward 2 |
| [M] Message Resources |
| + [m] Message Resource |
| [P] Plugins |
| + [p] Plugin 1 |
| |
+-----------------------------------------------------+
This table show, which will be displayed as label for the nodes
and what happened, when user select a node:
| Node |
Label |
Action after selecting |
Icons |
| Action mappings |
Action mappings |
Select whole content of the <action-mappings> element |
TBD |
| Action mapping |
Value of the path attribute of <action> element |
Select the appropriate action declaration |
TBD |
| Data Sources |
Data sources |
Select whole content of the <data-sources> element |
TBD |
| Data source |
Data source |
Select the appropriate data source declaration |
TBD |
| Form Beans |
Form Beans |
Select whole content of the <form-beans> element |
TBD |
| Form Bean |
Value of the name attribute of <form-bean> element |
Select the appropriate form bean declaration |
TBD |
| Global Exceptions |
Global Exceptions |
Select whole content of the <global-exceptions> element |
TBD |
| Global exception |
Value of the key attribute of <exception> element |
Select the appropriate exception declaration |
TBD |
| Global Forwards |
Global Forwards |
Select whole content of the <global-forwards> element |
TBD |
| Global Forward |
Value of the name attribute of <forward> element |
Select the appropriate forward declaration |
TBD |
| Message Resources |
Message Resources |
no action |
TBD |
| Message Resource |
Value of the parameter attribute of <message-resources> element |
Select the appropriate message resources declaration |
TBD |
| Plugins |
Plugins |
no action |
TBD |
| Plugin |
Value of the className attribute of <plug-in> element |
Select the appropriate plug-in declaration |
TBD |
The struts palette have for now only one item for generating forms in the JSP File.
This dialog will not be implemented in NetBeans 5.0.
Figure: Shows dialog for adding form to the JSP file.
+--------------------------------------------------------------------------------+
| Add Form |
+--------------------------------------------------------------------------------+
| |
| FormBean Class:|_______________________________________________| [ Browse... ] |
| |
| |
| Properties: |
| |____________Name__________|_________Type _________|_______Input Type________| |
| | name | String |_<html:text>___________v_| |
| | password | String |_<html:password>_______v_| |
| | id | Integer [] |_do not include__________| |
| | | | | |
| +--------------------------+-----------------------+-------------------------+ |
| |
| (o) Use <table> ( ) Use <br/> |
| |
| |
| [[ Add ]] [ Cancel ] [ Help ] |
+--------------------------------------------------------------------------------+
Components:
- FormBean Class - the full qualified name for the FormBean Class
-
Properties - The first and the second column are not editable.
The name and type are taken from the FormBean Classs. The last
column contains combo box which has these values:
- <html:text>
- <html:textarea>
- <html:password>
- <html:checkbox>
- <html:select>
- <html:radio>
- <html:file>
- <html:hidden>
- do not include
When user select do not include, then the property is not generated.
-
The options Use <table> a Use <br/> direct, how the
form will be generated.
Must have:
Should have:
Nice to have: