Hi,
If I understand you right, you are wondering (a) why the formbean gets
instantiated while building the view and (b) how you can get your data into
the form bean for display.
The normal processing is as follows: [user enters data in the html form]
- [HTTP request] - [form bean] which gets passed to the action class for
processing. Where you are incorrect is in assuming that in order to get
dynamic data into the next view, you need to populate the data into the form
bean of that view's form's action mapping. Not necessary. You can put the
data as beans in request/session scope under some name and you can use
struts' bean: or jstl's c: tags to output data from these beans (referring
to them by name) to html.
The only case where you will need to meddle with the form bean of the next
view is where the form should come pre-populated to the user. Struts example
contains a simple scenario where this is done; editRegistration page. There
are also long discussions in the user archive regarding the *right* way to
do form pre-population when the action does not have a reference to the form
bean of the next view and you do not want to chain actions. For example,
http://marc.theaimsgroup.com/?l=struts-userm=105058812426966w=2
http://marc.theaimsgroup.com/?l=struts-userm=103712789408751w=2
HTH,
Krishna
-Original Message-
From: Torsten Schlabach [mailto:[EMAIL PROTECTED]
Sent: Tuesday, May 27, 2003 7:57 PM
To: Struts Users Mailing List
Subject: RE: The Action, the bean and the JSP
But in whatever page I want to render I need to have the information that I
put into the bean corresponding to the action. For example, I would have
done
a lookup of the user's full name and want to render a page saying: Welcome
Joe Sixpack! and containing a form allowing the user to enter something
(let's say: open a ticket) and submit it to the new ticket action.
Of course the bean for the new ticket action will be a bean with ticket
attributes; not with the user's login attributes any more. But what Struts
does
is this: It looks up in my JSP form (supposed to render Welcome Joe
Sixpack) that the user might submit this form to new ticket, therefore
instantiate a ticket bean and put this in the context of the JSP page; so
Joe Sixpack
will be gone.
I don't even have a chance to put Joe's name into the ticket bean as an
additional field because that ticket bean is instantiated and put in for
the
login bean after the execute() method of the login action has finished; so I
have no access to that new bean and the page has no access to the old bean.
Got it? Does that make sense?
Torsten
You may need to render different views on basis of different conditions ..
Say if the login is invalid , then invalidlogin.jsp
If its a first time user then probably , enteruserpin.jsp ..
If you have a single attribute called output then this may not be
possible
..
and hence the forward
-Original Message-
From: Torsten Schlabach [mailto:[EMAIL PROTECTED]
Sent: Tuesday, May 27, 2003 7:17 PM
To: [EMAIL PROTECTED]
Subject: The Action, the bean and the JSP
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?