The DVDManager JavaBean
The workhorse bean from the JDOM article is
the DVDManager.
It'll build and keep a List of
JDOM Elements, where each Element describes a DVD. The important
methods are:
|
Method name |
Purpose |
|
buildDocument(String filename) |
Builds the List of JDOM Elements. |
|
int getNumberOfDvds() |
Returns the number of Elements in the List. |
|
setIndex(int index) |
Sets the index for an element in the List.
Must be called before the "getter" methods.
|
|
String getId()
String getTitle()
String getLength()
ArrayList getActors()
|
Get the DVD data. |
|
createDVD
(String id, String title, String length, ArrayList actors)
updateDVD
(String id, String title, String length, ArrayList actors)
|
Creates or updates a DVD. |
|
deleteDVD() |
Deletes the current DVD. |
|
save(String filename) |
Save the DVD data to an XML file |
- Table 1: The actions -
As you can see, these methods match nicely the 7 actions we'll
have to implement.
The 7 actions
One way to get started is to look at the 7 actions in more detail.
I use two tables for this. In the first
we'll write the purpose of the action, where it is initiated, and
where the result is presented. If the heading
contains a keyword in parentheses then it's used in the
action-mapping section in the struts-config file:
|
Action
(path)
|
Purpose |
Source page |
Target page
(forward)
|
|
list |
To list all DVDs |
Browser command line |
list.jsp |
|
detail |
To list details for a selected DVD |
list.jsp |
detail.jsp |
|
save |
To save the DVD data in the XML file |
list.jsp |
list.jsp |
|
create |
To create a new DVD entry |
detail.jsp |
detail.jsp |
|
update |
To update the selected DVD |
detail.jsp |
detail.jsp |
|
delete |
To delete the selected DVD |
detail.jsp |
list.jsp |
|
cancel |
To go to the list page |
detail.jsp |
list.jsp |
- Table 2: Action specs -
As can be seen this tells us about the intended flow between the
two pages. The "Action" and the "Target page"
information will end up in the struts-config.xml file. The
"Source page" is not needed for the config file, but I
feel it's a help when you define the actions. Note that in larger
applications an action may well have several
source pages.
The next table is directly related to the Struts config file
since it contains the names of the ActionForm and
Action classes. From my first article you'll recall that the
ActionForm is a class that holds data from an HTML
form. If you have a page with a form, then the action that
submits the form must have a defined ActionForm to
hold the form data. The Action class is where the business logic
starts, and it's invoked by the Struts servlet
controller. If the action has an associated ActionForm then the
Action class receives an instance of the
ActionForm.
The "Validate input" column is used to tell the controller
servlet if the ActionForm's validate method
should be called. You should only say "Yes" if the action
actually did submit a form and you want the contents
validated. The "detail" action only uses DetailForm to store the
data for display by the detail.jsp file, so
there's nothing to validate for this action. The "delete" action
deletes the current DVD, so again, there's
nothing to validate. If validation is wanted you must also enter
the name of a jsp-file where validation errors
can be shown. Normally this is done on the source page.
|
Action
(path) |
Action class
(type) |
ActionForm class
(name: points to the form-beans section) |
Validate input
(validate and input) |
|
list |
ListDVDAction |
- none needed - |
|
|
detail |
DetailDVDAction |
DetailForm |
No |
|
save |
SaveDVDAction |
- none needed - |
|
|
create |
CreateDVDAction |
DetailForm |
Yes - detail.jsp |
|
update |
UpdateDVDAction |
DetailForm |
Yes - detail.jsp |
|
delete |
DeleteDVDAction |
DetailForm |
No |
|
cancel |
- none needed - |
- none needed - |
|
- Table 3: Action specs -
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|