It's Junil
u, thank you.
I assume you are following the recommendation to
link only to actions. Doing this makes life a lot simpler and allows you to avoid scripting a great deal. Here's what I'm talking about:
first.jsp: contains a form, a hidden field - say employeeNum - without the value set, and a submit button. The form's action="first.do". first.do is associated with FirstAction which is associated with FirstForm. FirstForm would have getEmployeeNum() and setEmployeeNum(). I usually add a submit field in my forms to receive the value of the submit button. In the reset() method, I set the submit field to null.
Configure FirstAction with two forwards: say "display" and "process". The "display" forward will have the first.jsp as a target. The "process" forward will have "second.do" as its target.
FirstAction.perform() or execute() checks if the form (passed as a parameter) was submitted (submit != null). If not submitted, then retrieve the value for the employeeNum (from database or some bean already existing) and call the firstForm.setEmployeeNum(). Then return the "display" forward. This will process first.jsp and Struts will automatically set the value of the hidden employeeNum field. If the form was submitted, the employeeNum value is already in the request as a parameter so all you need to do is return the "process" forward, which will hand off control to the Action associated with "second.do", say SecondAction.
In the SecondAction.perform()/execute(), you can simply use request.getParameter() to get the employeeNum value and use it to prepopulate the second form, say SecondForm. If the employeeNum is also a field in SecondForm and that is all you need to be prepopulated, then don't have to do anything: Struts will automatically populate employeeNum with the value in the request parameter. You just return a "success" forward whose target is "second.jsp" which has a form whose action="second.do".
Clear as mud?
---
seem to be having some trouble posting messages today so sorry if I've confused you with my reply that I have since deleted
[ February 06, 2003: Message edited by: Junilu Lacar ]