The framework handles it. Here's a rough sequence of events:
1) The Struts servlet receives a request for /newinsurance.do
2) The request processor consults the mapping information and sees that there should be an InsuranceBean instance in the request
3) It checks the standard request attribute for the action form, sees that it is empty, and creates a new instance of the InsuranceForm bean, *then saves it to the request scope*
4) The AddInsuranceAction.execute method is called with a reference to this newly created bean
5) AddInsuranceAction sets attributes in this bean (Since Java objects are always passed by reference, those values are saved in the request-scope -- without any additional developer interaction.)
6) The request is forwarded to newinsurance.jsp
7) The Struts HTML tags in newinsurance.jsp look for a request-scoped InsuranceBean, and find the one that was created above. (If there was nothing there, they would be responsible for creating a new form.)
HTH, and I hope, also, that it is correct. I have done this, and I know that it works, but I may be a bit off in my explanation. I don't think I am, though.
-- Jeff
Roland Carlsson wrote:
Hi Jeff!
When you say that the newinsurance.jsp "just see it" where do you store "it"? In request.setAttribute() with some key? Session?
I'm using DynaValidatorBean but I guess that it should work in a simular way.
Thanks in advance Roland Carlsson
Den 04-11-11 14.14, skrev "Jeff Beal" <[EMAIL PROTECTED]>:
Every JSP page in my application is going to have two actions associated with it. One action will always be called prior to displaying the JSP page. The other will be called to process the user's input. In the struts-config, both of these actions are configured with the same form bean. Thus, when Action 1 is called, it has an instance of the ActionForm and that instance is already in the appropriate scope, etc. All I have to do is populate the values and the JSP page can display them.
struts-config.xml: <action path="/newinsurance" type="webmedx.web.common.actions.AddInsuranceAction" name="InsuranceBean" validate="false" scope="request"> <forward name="success" path="/newinsurance.jsp" redirect="false"> </forward> </action> <action path="/addInsurance" type="webmedx.web.common.actions.SaveInsuranceAction" name="InsuranceBean" validate="true" scope="request"> </action>
In my AddInsuranceAction, I can populate the InsuranceBean with information from the database and the newinsurance.jsp will "just see it".
-- Jeff
Roland Carlsson wrote:
Hi!
I am looking for a better way to pre-populate my (html)forms when building to allow the users to edit data from a database.
I know that I can create an populate a DynaValidatorBean but I don't know where to put it so that I can use it from my (html)from.
Thanks in advance Roland Carlsson
Ps: The mail-arcive doesn't work, so I appologize if I repost something that already have been answerd.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]