advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Coding your second Jakarta Struts Application :

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 -

How to Add Java Applets to Your Site

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.

 IBM Software Construction Toolbox
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 33
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

The Pitfalls of Open Source Litigation
LiMo Open to Working With Google on Mobile
Google Gadgets Under Attack at Black Hat
IBM, Linux and the Microsoft-Free PC
Opengear's Open Source Odyssey
Sun Moves JavaFX Closer to Primetime
Will LSB 4 Standardize Linux?
Making a Case for an Android-Symbian Merger
Ubuntu Launchpad Opens Up Development
BT Buys Voice Software Startup

An Introduction to F# for Functional Programming
The Basics of REALbasic, Cross-platform RAD Tool in the Mold of VB
Silverlight Streaming: Free Video Hosting for All
What's New in ASP.NET 3.5?
Putting SharePoint to Work for You
Putting Intel® Threading Building Blocks to Work
Achieve the Best of Two Worlds with Behavior-Driven Development
Understanding Windows Mobile Security
RODCs Transform Branch Office Security
SQL Server 2008 Express: The Free Database from Microsoft

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers