jQuery in Action, 2nd edition*
The moose likes Struts and the fly likes DispatchAction question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "DispatchAction question" Watch "DispatchAction question" New topic
Author

DispatchAction question

Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
hi, good day
if i have 10 pages which contain 1 submit button, all pages contain 1 form which allow user keyin data, when user click button, the page will send and save data into database

my question, should i use dispatchAction? do i still need actionform for each page if using dispatchAction?

i using normal html code rather than struts build-in html tag, would it work fine in dispatchAction ?

thank you very much for your time !!
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
Hi Alvin,

From your mail, it appears that the purpose of the 10 pages is solely for data collection. The only "true" action that will be performed would be on the last page when data would get stored in the database.

Your question is whether to use DispatchAction or Action. Right?
In either case, I would recommend using a single form bean (session scope), since all the data collected would be related (mutli-page form).
If you still want to use a seperate FormBean for each screen, you would be responsible to collecting and holding the information entered as the user navigates through the 10 screens. Form validation would be easy in this case. But again, I wouldn't recommend this approach.

Using a seperate action for each page would probably not be worthwhile, since the first 9 pages do not perform any action as such. You are probably only gathering information and validating it on each page.

There are 2 approaches I can think of (using single form bean). You can evaluate both of them.
1. Using DispatchAction
- 9 methods would be just for flow control and one to perform/initiate your business functionality.
- If you are using xml based validation, you can use the page attribute of the field element.

2. Use 1 "type" action-mapping and 9 "forward" action-mappings.
- The first 9 pages would not be processed by any action method. Only validation + forward to next page.
- The last page submit would be to an action for storing to database.
- If you are using xml based validation, you can use ValidatorActionForm, maybe.
- Drawback: 10 action-mappings in struts-config.xml

The choice is yours to make. Let us know what you have decided to do and why, also, if you have thought of something better.

Note: If you are not going to use struts tag libraries for databinding the html controls to the form bean, then you are on your own if you need to display validation errors on the same page where they occur.

Sheldon
[ September 09, 2004: Message edited by: Sheldon Fernandes ]
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
hi, good day, Sheldon Fernandes ..my case is not send data to database in last page, but for every single html page..meaning every page will have a button to click for action
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: DispatchAction question