Torsten Schlabach wrote:

Dear List,

I am working with Struts for some weeks now, but there are just some
concepts that don't become clear to me neither from the docs nor from all that
tutorials. They all stop where my questions start. So first of all, I would like
to ask the list for confirmation on what I found out / understood so far.

Is it right that in a web browser environment:
a) everyhting starts with a request coming in
b) and the result of that is some web page beeing rendered in the browser
c) all that Struts (and other methodologies for application login in such an
environment) are about taking the input from the request to somehow generate
the output being sent to the browser
d) The request - response thing is stateless meaning that while processing a
request neither myself nor the framework should care about the preceeding or
potential following requests (with the little exception of *optionally*
keeing a session state in some session content)

Working from that assumption, I exlained to myself that this is what happens
inside Struts when a request comes in:

- The ActionServlet determines the appropriate action from the
struts-config.xml.
- In case that action has a form bean associated with it, it instantiates
that form bean and fills it with the request parameters.
- After that it calls the execute method on the Action passing the (now
filled) form bean instance in as a parameter.
- The code in the execute method can read information from the FormBean, do
calculations, lookups, whatever and write results back into the form bean.
- The execute method returns control to the ActionServlet letting it know
which JSP page to render (choosing either from local or global forwards).
- The JSP page is rendered using the FormBean (still the same one?!?) as a
data source and sent back to the broser?

Am I right or wrong until here?



Sounds fairly correct.


In case I am right (and in case I am wrong, too), please help me understand:

- Why do I need to use a *forward* to display the output page? (My
understand of forward would be: I am being sent somewhere else than I originally
intended to go.) It would be much more logical to me if my <action> in
stuts-config.xml had a "output" attribute (similar to the "input" attribute) that names
the page that I want to use to render the results of the action.


Your definition of forward is closer to the definition of "redirect". Forwarding is just transferring control (usually to a JSP page to render the view).
The reason its possible to to forward to more than one location, rather than just a single "output" attribute is that the action may have different outputs depending on some logic (for example I have a search action which returns one of three forwards depending on whether 0,1 or multiple items are found).


- If the results page contains a form that has an action associated to it
that the user *might* fire by clicking "submit" on the rendered page (he or she
could as well use a link to go somewhere else) Struts will instantiate the
form bean for that potential request already before even rendering the page
containing the form that will enable the user to make that request later (or
leave it). What's the sense in here?


There are generally two actions involved in handling user input with forms.

Step 1. The user follows a link to a page with a form - for example, Edit user details.

Request --> Action1 --> EditUserForm.jsp

Step 2. The user hits the submit button after filling in the form.

Request --> Action2 --> confirmation.jsp

Both actions will be associated with same form in the struts-config.xml - lets call it newUserForm.
Before calling Action1.execute() Struts will instantiate a new newUserForm and call execute. The action may then wish to preopulate this form with some data from the model ie. from the database. In this case it will be the users current details. The action then forwards to the EditUserForm.jsp via a local forward (if errors occurred when loading the user data or some flag was set or something then perhaps the action might forward to a different location :-). The jsp can then render the filled in values as HTML form controls.
The Action form instantiated for Action2 will be populated with the values that were filled in by the user. Action2 can then submit these to the database.


I am sure I got at least one concept wrong. Please enlighten me.

Torsten



Hope this helps (sorry if i spelled things out a bit slowly)

Gareth


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to