I am learning struts. I have a doubt about the Action Form when its in Request scope. I hav a url which maps to an Action say FirstAction. I have associated a form ShareForm with this action FirstAction. The scope of the ShareForm is request. In FirstAction I retrieve all the details of the attributes in the ShareForm. Now from FirstAction I have forwarded to a new action SecondAction which also has the same form (ShareForm). My question is will the data which i retrieved in FirstAction from the ShareForm will also be available to SecondAction or is it that the form would be reset before being used in SecondAction.
I have seen a bit conflicting behavior so just wanted to clarify
When the user presses the submit button on the Jsp1, all inputs on that form are populated into ShareForm. If FistAction puts data into ShareForm for which there is no input on JSP1, that data is lost.
I am not modifying the form in the FirstAction. I will only fetch values from it & then forward it to the secondAction. So in this case the expected behavior is that the form is available in the secondAction in the same way as it was in the FirstAction with all values intact.
And if i modify the form in the firstAction then all the form values which the form had when it was populated in initial input JSP & fetched in the firstAction would be reset & what i get in the secondAction is the new instance of the ShareForm.
Thanks & Regards
posted 14 years ago
This is basically correct. However, I would like to clarify one point:
Regardless of whether you change the values or not, the instance of ShareForm that SecondAction receives will always be a new instance if the ActionForm is in request scope. When the JSP is submitted, Struts creates a new instance of the ActionForm and repopulates it with the input values from the JSP.