Struts Novice: Using Action/ActionForms?

G

gilgantic

Few random questions about Struts:
(Note: I left out ActionServlet and Model classes out of my questions)
1. Should every JSP have one "ActionForm" and "Action" class associated with it?
2. Is Action-to-Action (Action Chaining) possible? If so, is it a good practice?
3. Is the normal flow JSP (POST)-> Action -> ActionForward -> ActionForm -> JSP?
 
S

Sudsy

gilgantic said:
Few random questions about Struts:
(Note: I left out ActionServlet and Model classes out of my questions)
1. Should every JSP have one "ActionForm" and "Action" class associated with it?
2. Is Action-to-Action (Action Chaining) possible? If so, is it a good practice?
3. Is the normal flow JSP (POST)-> Action -> ActionForward -> ActionForm -> JSP?

Start here:
<http://www.sudsy.net/technology/struts-arch.html>
Then read the other articles in the same family.
To answer your questions:
1. Not necessarily. That's not ducking the question, BTW. You might have
a search facility included on the page which would submit to a
different action.
2. Certainly possible but you'd have to carefully consider the potential
for side-effects.
3. No. POST->ActionForm->Action->ActionForward->JSP. The article I cited
includes a nice flow-chart.
 
L

Larry

See below...

gilgantic said:
Few random questions about Struts:
(Note: I left out ActionServlet and Model classes out of my questions)
1. Should every JSP have one "ActionForm" and "Action" class associated
with it?
Normally, yes. If your JSP has a <form> tag and POST, then you should have
an ActionForm for validation of the form data and an Action to process the
form.
2. Is Action-to-Action (Action Chaining) possible? If so, is it a good
practice?
An Action class is just a hybrid Servlet, so and Action class can call
another action class. Typically, you would call another JSP to display
results, etc. We have used Actions to call another Action in special cases
(like passing data from a process type Action to an Action that generates a
list of that data).
3. Is the normal flow JSP (POST)-> Action -> ActionForward ->
ActionForm -> JSP?
The processing flow is JSP -> ActionServlet -> ActionForm -> Action -> JSP.
ActionServlet (the Controller) is called behind-the-scenes via your mapping
in struts-config.xml, which in turn calls your ActionForm. The ActionForm
(just a JavaBean container for data) must be loaded with the data from your
JSP so the Action can "execute" it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top