Struts workflow

D

Daniel

Hi,

I'm trying to understand the workflow in struts, and have some
difficulties. I want to load a form and submit it. Then I want to go
to one of several pages (which are also part of the form).

In the form I have some data that needs to be loaded in selects and
multiple checkboxes. To do this, it seems I should use beans.
First question, how do I define this in the struts-config.xml?

I'm using tiles, so in the tiles-config it looks like this:
<definition name=".testForm" extends=".main.layout">
<put name="left" value="/pages/left.jsp" />
<put name="body" value="/pages/test.jsp" />
</definition>

In the struts-config.xml:
<forward
name="testForm"
path="/testForm.do"/>
....

<action
path="/testForm"
forward=".testForm"/>

Where do I add the beans I need. And where do I load the data into
them?
If I add an action type, how do I forward it?
<action
path="/testForm"
type="test.TestAction"
forward=".testForm"/>

In the test action class I can load the data into beans, I suppose;
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
HashMap items = getItems();
//request.setAttribute("items", items);
//servlet.getServletContext().setAttribute("items", items);
HttpSession session = request.getSession();
session.setAttribute("items", items);

return mapping.findForward("testForm");
}

I could connect to the database and populate a HashMap in the getItems
method.
But what about the findForward? Doesn't that lead back to the very
same action - like an iternal loop?
If so, do I need to create a new action, that forwards to this one?

<action
path="/testForm"
type="test.TestAction"
forward=".testForm"/>
...
<action
path="/testForm2"
forward=".testForm2"/>
...
return mapping.findForward("testForm2");


I guess there is no use to continue before I got these things sorted
out.


Thanks in advance for your help!
 
J

John

Daniel,
You are making this first attempt at Struts more difficult that you
need it to be. Drop the tile for now, and factor it in later. You first
need to get a simple app up and running.

Here is the workflow you requested:

1. A request comes in with a .do extension, the container maps it to
the ActionServlet.
2. The ActionServlet acts like a front end controller and dispatches
control to a RequestProcessor.
3. The RequestProcessor finds an action tag with a path attribute that
matches the incoming request
4. Then the RequestProcessor looks for a form-bean tag that has a name
attribute that matched the action tags name attribute.
5. RequestProcessor instantiates a FormBean of the of based on the type
attribute
6. RequestProcessor calls populates the FormBeans fields from the
incoming request, then calls its reset method, then its validate method
7. RequestProcessor instantiates an Action based on the action tags
type attribute
8. RequestProcessor calls the action's execute method which returns
an ActionForward.
9. The RequestProcessor finds a matching ActionForward first within the
nested forward tags, then from within the global-forwards tag.
Note: if the validate method returns an ActionMessage then the
RequestProcessor forward the request to the resource specified in the
action's input attribute

Again start with the basics:
http://www.reumann.net/struts/main.do -- all meat, no the bs has been
trimmed out. Do not skip this, you will give you a great jump start.

"Mastering Jakarta Struts" - again all meet, no bs. This book goes
into more detail. It also has a complete app with database calls. I
highly recomend this book to people, by the time you finish this you
will understand Struts.

Good luck!

---------------------
 
S

Sudsy

John wrote:
"Mastering Jakarta Struts" - again all meet, no bs. This book goes
into more detail. It also has a complete app with database calls. I
highly recomend this book to people, by the time you finish this you
will understand Struts.

The workflow described by John is likely correct (I only had time for a
cursory examination). I will recommend another book, one which I wish I
had in my library from the outset. Then again, the copyright is 2003...
It's "Programming Jakarta Struts" by Chuck Cavaness, ISBN 0-596-00328-5.
If you read this ng on a regular basis or search the archives then you'd
discover that I always recommend this tome, and for good reason!
It covers elements such as validation and Tiles in such a way as to make
many of the articles I wrote seem pale by comparison...
Maybe if I'd beaten him to the punch...
Seriously, it's a great book which deserves a place on the bookshelf of
anyone developing Struts apps. My copy is getting dog-eared and has a
lot of post-it(tm) labels which permit me to jump to the relevant
sections easily.

Disclaimer: I have no personal or professional association with either
the author or publisher of this book. Ask them!
 
Joined
Jun 15, 2007
Messages
1
Reaction score
0
Struts 2 Workflow

Hi, can any one send struts 2 workflow steps? I want work on struts 2 all my new projects.

Thanks.
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top