Initialize Struts form with request parameters
Hi all, I have a problem with struts form. The form is: html:form action=chooseTrainee html:hidden property=traineeId/ html:text property=name/ html:submit value=Submit/ /html:form and the ActionForm has the following properties (fields and getters/setters): traineeId name What I want is: the traineeId must be initialized by a value passed via URL: e.g: http://localhost/test/chooseTraineePage.jsp?traineeId=12345 How can I do that? Your reply is highly appreciated! Thanks Tien -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 01, 2003 3:08 PM To: [EMAIL PROTECTED] Subject: struts-user Digest 1 Jul 2003 13:07:49 - Issue 3513 struts-user Digest 1 Jul 2003 13:07:49 - Issue 3513 Topics (messages 84024 through 84051): show selected value in html:options field 84024 by: Stefan Schaebel Re: logic:equal with sessionAttributes 84025 by: Nicolas De Loof 84026 by: Filip Polsakiewicz Re: [ANNOUNCEMENT] Struts 1.1 Final released 84027 by: Arnaud HERITIER Re: Can I have a nbsp; _not_ URL encoded? 84028 by: Marco Maier 84029 by: Samuel.Opoku-Boadu.t-systems.com Re: setting input for action 84030 by: thart.part.net Validations in Struts 1.0 84031 by: sriram Populating select boxes dynamically 84032 by: sriram 84043 by: Alex Shneyderman disabling form element 84033 by: Frances Aleah Z. de Guzman 84034 by: Mark Lowe REPOST: Help! - java.security.AccessControlException 84035 by: White, Joshua A (HTSC, CASD) Problem With Struts1.1 Example 84036 by: Saroj Kumar Choudhury knowing which DispatchAction called an Action 84037 by: Ionel Gardais where does a form element get and put it's data 84038 by: Heather Buch 84040 by: Adam Hardy Newbie question: DispatchAction subclassing 84039 by: Paula Coll Upgrading to Struts 1.1 84041 by: Natalie D Rassmann 84051 by: Hajratwala, Nayan (N.) Display table contents 84042 by: Arnost Foo Tag to remove jsp from cache??? 84044 by: Prashanth.S 84046 by: Alex Shneyderman 84048 by: Nicolas De Loof External style sheets and tiles. 84045 by: James Watkins 84047 by: Nicolas De Loof Could not parse deployment descriptor: java.io.IOException: cannot resolve '/WEB-INF/struts-bean.tld' into a valid tag library 84049 by: PREETAM Balijepalli 84050 by: Adam Hardy Administrivia: To subscribe to the digest, e-mail: [EMAIL PROTECTED] To unsubscribe from the digest, e-mail: [EMAIL PROTECTED] To post to the list, e-mail: [EMAIL PROTECTED] -- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Initialize Struts form with request parameters
Well, honestly it isn't recommended that you do things this way. Struts is all about separating your model from your view, and you are wanting to modify the model. That's smack dab in the realm of Actions, so you should be doing it there. The Action would then forward to your JSP. Modifying ActionForms from within a JSP flies in the face of what Struts was designed to do. What you'll want to do is have an Action that gets called before your JSP is displayed. You're URL would look like this: http://localhost/test/chooseTraineePage.do?traineeId=12345 The .do is the only difference. From within the mapping defined in your struts-config for chooseTraineePage you would have the following (in your execute/perform method): ChooseTraineeForm ctForm = (ChooseTraineeForm) form; ctForm.setTraineeId(request.getParameter(traineeId)); ctForm.setName(request.getParameter(name)); request.addParameter(chooseTrainee, ctForm); return mapping.findForward(success); This is off the top of my head, so the syntax may be wrong, but the flow is correct. -= James -Original Message- From: Tien Nguyen [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 01, 2003 9:07 AM To: 'Struts Users Mailing List'; [EMAIL PROTECTED] Subject: Initialize Struts form with request parameters Hi all, I have a problem with struts form. The form is: html:form action=chooseTrainee html:hidden property=traineeId/ html:text property=name/ html:submit value=Submit/ /html:form and the ActionForm has the following properties (fields and getters/setters): traineeId name What I want is: the traineeId must be initialized by a value passed via URL: e.g: http://localhost/test/chooseTraineePage.jsp?traineeId=12345 How can I do that? Your reply is highly appreciated! Thanks Tien -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 01, 2003 3:08 PM To: [EMAIL PROTECTED] Subject: struts-user Digest 1 Jul 2003 13:07:49 - Issue 3513 struts-user Digest 1 Jul 2003 13:07:49 - Issue 3513 Topics (messages 84024 through 84051): show selected value in html:options field 84024 by: Stefan Schaebel Re: logic:equal with sessionAttributes 84025 by: Nicolas De Loof 84026 by: Filip Polsakiewicz Re: [ANNOUNCEMENT] Struts 1.1 Final released 84027 by: Arnaud HERITIER Re: Can I have a nbsp; _not_ URL encoded? 84028 by: Marco Maier 84029 by: Samuel.Opoku-Boadu.t-systems.com Re: setting input for action 84030 by: thart.part.net Validations in Struts 1.0 84031 by: sriram Populating select boxes dynamically 84032 by: sriram 84043 by: Alex Shneyderman disabling form element 84033 by: Frances Aleah Z. de Guzman 84034 by: Mark Lowe REPOST: Help! - java.security.AccessControlException 84035 by: White, Joshua A (HTSC, CASD) Problem With Struts1.1 Example 84036 by: Saroj Kumar Choudhury knowing which DispatchAction called an Action 84037 by: Ionel Gardais where does a form element get and put it's data 84038 by: Heather Buch 84040 by: Adam Hardy Newbie question: DispatchAction subclassing 84039 by: Paula Coll Upgrading to Struts 1.1 84041 by: Natalie D Rassmann 84051 by: Hajratwala, Nayan (N.) Display table contents 84042 by: Arnost Foo Tag to remove jsp from cache??? 84044 by: Prashanth.S 84046 by: Alex Shneyderman 84048 by: Nicolas De Loof External style sheets and tiles. 84045 by: James Watkins 84047 by: Nicolas De Loof Could not parse deployment descriptor: java.io.IOException: cannot resolve '/WEB-INF/struts-bean.tld' into a valid tag library 84049 by: PREETAM Balijepalli 84050 by: Adam Hardy Administrivia: To subscribe to the digest, e-mail: [EMAIL PROTECTED] To unsubscribe from the digest, e-mail: [EMAIL PROTECTED] To post to the list, e-mail: [EMAIL PROTECTED] -- - 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]
Re: Initialize Struts form with request parameters
This would happen automatically if you access the JSP via an action mapping in your struts-config. You specify the action class, the action form and the forward/jsp. struts will automatically instantiate the form when the request comes in and populate the form properties with any equivalent request parameters. hth Adam Tien Nguyen wrote: Hi all, I have a problem with struts form. The form is: html:form action=chooseTrainee html:hidden property=traineeId/ html:text property=name/ html:submit value=Submit/ /html:form and the ActionForm has the following properties (fields and getters/setters): traineeId name What I want is: the traineeId must be initialized by a value passed via URL: e.g: http://localhost/test/chooseTraineePage.jsp?traineeId=12345 How can I do that? Your reply is highly appreciated! Thanks Tien -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 01, 2003 3:08 PM To: [EMAIL PROTECTED] Subject: struts-user Digest 1 Jul 2003 13:07:49 - Issue 3513 struts-user Digest 1 Jul 2003 13:07:49 - Issue 3513 Topics (messages 84024 through 84051): show selected value in html:options field 84024 by: Stefan Schaebel Re: logic:equal with sessionAttributes 84025 by: Nicolas De Loof 84026 by: Filip Polsakiewicz Re: [ANNOUNCEMENT] Struts 1.1 Final released 84027 by: Arnaud HERITIER Re: Can I have a nbsp; _not_ URL encoded? 84028 by: Marco Maier 84029 by: Samuel.Opoku-Boadu.t-systems.com Re: setting input for action 84030 by: thart.part.net Validations in Struts 1.0 84031 by: sriram Populating select boxes dynamically 84032 by: sriram 84043 by: Alex Shneyderman disabling form element 84033 by: Frances Aleah Z. de Guzman 84034 by: Mark Lowe REPOST: Help! - java.security.AccessControlException 84035 by: White, Joshua A (HTSC, CASD) Problem With Struts1.1 Example 84036 by: Saroj Kumar Choudhury knowing which DispatchAction called an Action 84037 by: Ionel Gardais where does a form element get and put it's data 84038 by: Heather Buch 84040 by: Adam Hardy Newbie question: DispatchAction subclassing 84039 by: Paula Coll Upgrading to Struts 1.1 84041 by: Natalie D Rassmann 84051 by: Hajratwala, Nayan (N.) Display table contents 84042 by: Arnost Foo Tag to remove jsp from cache??? 84044 by: Prashanth.S 84046 by: Alex Shneyderman 84048 by: Nicolas De Loof External style sheets and tiles. 84045 by: James Watkins 84047 by: Nicolas De Loof Could not parse deployment descriptor: java.io.IOException: cannot resolve '/WEB-INF/struts-bean.tld' into a valid tag library 84049 by: PREETAM Balijepalli 84050 by: Adam Hardy Administrivia: To subscribe to the digest, e-mail: [EMAIL PROTECTED] To unsubscribe from the digest, e-mail: [EMAIL PROTECTED] To post to the list, e-mail: [EMAIL PROTECTED] -- - 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]
Re: Initialize Struts form with request parameters
Adam's answer is absolutely correct, however let me add more details to make your job a little bit easier. 1. Create and action called loadTrainee.do and associate this action with your form. with a forward to chooseTraineePage.jsp 2. Invoke chooseTranies.do?traineeId=, struts, will call the action in 1 and automatically populate your form's traineeId for you 3. In action1, write some code to use traineeId to fill name, struts will then forward your form to chooseTraineePage.jsp to display In summary, you need 2 actions, one to to load the form and the other one is to manipulate the form Hope this helps -D - Original Message - From: Adam Hardy [EMAIL PROTECTED] Newsgroups: Struts Sent: Tuesday, July 01, 2003 7:26 AM Subject: Re: Initialize Struts form with request parameters This would happen automatically if you access the JSP via an action mapping in your struts-config. You specify the action class, the action form and the forward/jsp. struts will automatically instantiate the form when the request comes in and populate the form properties with any equivalent request parameters. hth Adam Tien Nguyen wrote: Hi all, I have a problem with struts form. The form is: html:form action=chooseTrainee html:hidden property=traineeId/ html:text property=name/ html:submit value=Submit/ /html:form and the ActionForm has the following properties (fields and getters/setters): traineeId name What I want is: the traineeId must be initialized by a value passed via URL: e.g: http://localhost/test/chooseTraineePage.jsp?traineeId=12345 How can I do that? Your reply is highly appreciated! Thanks Tien -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 01, 2003 3:08 PM To: [EMAIL PROTECTED] Subject: struts-user Digest 1 Jul 2003 13:07:49 - Issue 3513 struts-user Digest 1 Jul 2003 13:07:49 - Issue 3513 Topics (messages 84024 through 84051): show selected value in html:options field 84024 by: Stefan Schaebel Re: logic:equal with sessionAttributes 84025 by: Nicolas De Loof 84026 by: Filip Polsakiewicz Re: [ANNOUNCEMENT] Struts 1.1 Final released 84027 by: Arnaud HERITIER Re: Can I have a nbsp; _not_ URL encoded? 84028 by: Marco Maier 84029 by: Samuel.Opoku-Boadu.t-systems.com Re: setting input for action 84030 by: thart.part.net Validations in Struts 1.0 84031 by: sriram Populating select boxes dynamically 84032 by: sriram 84043 by: Alex Shneyderman disabling form element 84033 by: Frances Aleah Z. de Guzman 84034 by: Mark Lowe REPOST: Help! - java.security.AccessControlException 84035 by: White, Joshua A (HTSC, CASD) Problem With Struts1.1 Example 84036 by: Saroj Kumar Choudhury knowing which DispatchAction called an Action 84037 by: Ionel Gardais where does a form element get and put it's data 84038 by: Heather Buch 84040 by: Adam Hardy Newbie question: DispatchAction subclassing 84039 by: Paula Coll Upgrading to Struts 1.1 84041 by: Natalie D Rassmann 84051 by: Hajratwala, Nayan (N.) Display table contents 84042 by: Arnost Foo Tag to remove jsp from cache??? 84044 by: Prashanth.S 84046 by: Alex Shneyderman 84048 by: Nicolas De Loof External style sheets and tiles. 84045 by: James Watkins 84047 by: Nicolas De Loof Could not parse deployment descriptor: java.io.IOException: cannot resolve '/WEB-INF/struts-bean.tld' into a valid tag library 84049 by: PREETAM Balijepalli 84050 by: Adam Hardy Administrivia: To subscribe to the digest, e-mail: [EMAIL PROTECTED] To unsubscribe from the digest, e-mail: [EMAIL PROTECTED] To post to the list, e-mail: [EMAIL PROTECTED] -- - 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]