RE: Maintaining form data across pages...
I fear that some of this contains a misunderstanding at a deeper level. You can control all this by coding what you want in the reset() method. The actual code (in part) is as follows: form.setServlet(this.servlet); form.reset(mapping, request); if (mapping.getMultipartClass() != null) { request.setAttribute(Globals.MULTIPART_KEY, mapping.getMultipartClass()); } RequestUtils.populate(form, mapping.getPrefix(), mapping.getSuffix(), request); The RequestUtils code (in part) follows: while (names.hasMoreElements()) { String name = (String) names.nextElement(); String stripped = name; if (prefix != null) { if (!stripped.startsWith(prefix)) { continue; } stripped = stripped.substring(prefix.length()); } if (suffix != null) { if (!stripped.endsWith(suffix)) { continue; } stripped = stripped.substring(0, stripped.length() - suffix.length()); } if (isMultipart) { properties.put(stripped, multipartParameters.get(name)); } else { properties.put(stripped, request.getParameterValues(name)); } } // Set the corresponding properties of our bean try { BeanUtils.populate(bean, properties); } catch (Exception e) { throw new ServletException("BeanUtils.populate", e); } The BeanUtils code follows: // Loop through the property name/value pairs to be set Iterator names = properties.keySet().iterator(); while (names.hasNext()) { // Identify the property name and value(s) to be assigned String name = (String) names.next(); if (name == null) { continue; } Object value = properties.get(name); // Perform the assignment for this property setProperty(bean, name, value); } This is all there is to it. That is fairly easy to track and does not provide any mysteries that cannot be controlled by the judicious coding of the reset() method. Hope this is helpful. Michael McGrady At 04:58 AM 5/16/2004, ayouaa0a wrote: Sounds great, ISA, I will make a sample and post it over the group :) -Original Message- From: Jonathan Roberts [mailto:[EMAIL PROTECTED] Sent: Sunday, May 16, 2004 2:44 PM To: Struts Users Mailing List Subject: RE: Maintaining form data across pages... Ashraf, Why dont you add this to the site once you have resolved the architecture and code issues - sounds like an issue that alot of people may come across! Jon ayouaa0a <[EMAIL PROTECTED]> wrote: Thanks very much, u have been of a great help :) -Original Message- From: Andrea M [mailto:[EMAIL PROTECTED] Sent: Sunday, May 16, 2004 2:06 PM To: 'Struts Users Mailing List' Subject: R: Maintaining form data across pages... Yes that's the way it works It does not matter in which scope the form is set 1. JSP submits the form 2. Struts goes to find one in the scope you told him 3. if it finds one, then it calls reset() (so to avoid having stale data), then populates it 4. it it doesn't find any form in the scope, then istantiates a new one then carries on This is because Struts doesn't know if the actionform it founds is being populated by a multiple-page form, or is simply a stale one. And this is why reset() takes httpServletRequest as parameter: so you can implement your own reset logic depending on your particular application flow -Messaggio originale- Da: ayouaa0a [mailto:[EMAIL PROTECTED] Inviato: domenica 16 maggio 2004 12.40 A: 'Struts Users Mailing List' Oggetto: RE: Maintaining form data across pages... Yes, that's what I want, I will give it a try. but what do u mean struts "always calls reset()" everytime it access the form, this is very strange, even the form is in session!! Plz domonstrate more, as far as I understood: 1- When a JSP submits a form. 2- Struts calls reset for the form. 3- Try to populate the form from the JSP controls, even it was in session. -Original Message- From: Andrea M [mailto:[EMAIL PROTECTED] Sent: Sunday, May 16, 2004 1:11 PM To: 'Struts Users Mailing List' Subject: R: Maintaining form data across pages... Hi I'm not sure I've understood properly what you need What I understand is that you are trying to populate the same actionform using several pages. The problem is that struts *always calls reset()* every time it access the form. What you can do is making your pages set a flag in the request, so your form can know where it's called from. Reset() method takes httpServletRequest as parameter, so you can implement conditional logic there... sometimes like: public void reset(ActionMa
RE: Maintaining form data across pages...
Sounds great, ISA, I will make a sample and post it over the group :) -Original Message- From: Jonathan Roberts [mailto:[EMAIL PROTECTED] Sent: Sunday, May 16, 2004 2:44 PM To: Struts Users Mailing List Subject: RE: Maintaining form data across pages... Ashraf, Why dont you add this to the site once you have resolved the architecture and code issues - sounds like an issue that alot of people may come across! Jon ayouaa0a <[EMAIL PROTECTED]> wrote: Thanks very much, u have been of a great help :) -Original Message- From: Andrea M [mailto:[EMAIL PROTECTED] Sent: Sunday, May 16, 2004 2:06 PM To: 'Struts Users Mailing List' Subject: R: Maintaining form data across pages... Yes that's the way it works It does not matter in which scope the form is set 1. JSP submits the form 2. Struts goes to find one in the scope you told him 3. if it finds one, then it calls reset() (so to avoid having stale data), then populates it 4. it it doesn't find any form in the scope, then istantiates a new one then carries on This is because Struts doesn't know if the actionform it founds is being populated by a multiple-page form, or is simply a stale one. And this is why reset() takes httpServletRequest as parameter: so you can implement your own reset logic depending on your particular application flow -Messaggio originale- Da: ayouaa0a [mailto:[EMAIL PROTECTED] Inviato: domenica 16 maggio 2004 12.40 A: 'Struts Users Mailing List' Oggetto: RE: Maintaining form data across pages... Yes, that's what I want, I will give it a try. but what do u mean struts "always calls reset()" everytime it access the form, this is very strange, even the form is in session!! Plz domonstrate more, as far as I understood: 1- When a JSP submits a form. 2- Struts calls reset for the form. 3- Try to populate the form from the JSP controls, even it was in session. -Original Message- From: Andrea M [mailto:[EMAIL PROTECTED] Sent: Sunday, May 16, 2004 1:11 PM To: 'Struts Users Mailing List' Subject: R: Maintaining form data across pages... Hi I'm not sure I've understood properly what you need What I understand is that you are trying to populate the same actionform using several pages. The problem is that struts *always calls reset()* every time it access the form. What you can do is making your pages set a flag in the request, so your form can know where it's called from. Reset() method takes httpServletRequest as parameter, so you can implement conditional logic there... sometimes like: public void reset(ActionMapping mapping, HttpServletRequest request) { // first time accessed so I can set everything to null if (request.getParameter("flag") == null) { // set all properties to null here } else if (request.getParameter("flag").equals("page1") { // set to null only properties not present in page1 } else if (request.getParameter("flag").equals("page2") { // set to null only properties not present in page2 } ... } -Messaggio originale- Da: Ayoub, Ashraf A [mailto:[EMAIL PROTECTED] Inviato: domenica 16 maggio 2004 11.58 A: Struts Users Mailing List Oggetto: Maintaining form data across pages... Dears, I am trying to setup a series of jsp pages (requestForm, confrimation jsp). I set the scope of my requestForm to "session" as to maintain the data across the various jsps, but I get it as if reset is called, after the confirmation page submits. What is the best way to maintain the request data across several jsp pages, speically I have lots of pages as step 1, step 2, step 3 before submiting the action, with different form beans. Thanks, best regards Ashraf Fouad - 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] - 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] - Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Maintaining form data across pages...
Ashraf, Why dont you add this to the site once you have resolved the architecture and code issues - sounds like an issue that alot of people may come across! Jon ayouaa0a <[EMAIL PROTECTED]> wrote: Thanks very much, u have been of a great help :) -Original Message- From: Andrea M [mailto:[EMAIL PROTECTED] Sent: Sunday, May 16, 2004 2:06 PM To: 'Struts Users Mailing List' Subject: R: Maintaining form data across pages... Yes that's the way it works It does not matter in which scope the form is set 1. JSP submits the form 2. Struts goes to find one in the scope you told him 3. if it finds one, then it calls reset() (so to avoid having stale data), then populates it 4. it it doesn't find any form in the scope, then istantiates a new one then carries on This is because Struts doesn't know if the actionform it founds is being populated by a multiple-page form, or is simply a stale one. And this is why reset() takes httpServletRequest as parameter: so you can implement your own reset logic depending on your particular application flow -Messaggio originale- Da: ayouaa0a [mailto:[EMAIL PROTECTED] Inviato: domenica 16 maggio 2004 12.40 A: 'Struts Users Mailing List' Oggetto: RE: Maintaining form data across pages... Yes, that's what I want, I will give it a try. but what do u mean struts "always calls reset()" everytime it access the form, this is very strange, even the form is in session!! Plz domonstrate more, as far as I understood: 1- When a JSP submits a form. 2- Struts calls reset for the form. 3- Try to populate the form from the JSP controls, even it was in session. -Original Message- From: Andrea M [mailto:[EMAIL PROTECTED] Sent: Sunday, May 16, 2004 1:11 PM To: 'Struts Users Mailing List' Subject: R: Maintaining form data across pages... Hi I'm not sure I've understood properly what you need What I understand is that you are trying to populate the same actionform using several pages. The problem is that struts *always calls reset()* every time it access the form. What you can do is making your pages set a flag in the request, so your form can know where it's called from. Reset() method takes httpServletRequest as parameter, so you can implement conditional logic there... sometimes like: public void reset(ActionMapping mapping, HttpServletRequest request) { // first time accessed so I can set everything to null if (request.getParameter("flag") == null) { // set all properties to null here } else if (request.getParameter("flag").equals("page1") { // set to null only properties not present in page1 } else if (request.getParameter("flag").equals("page2") { // set to null only properties not present in page2 } ... } -Messaggio originale- Da: Ayoub, Ashraf A [mailto:[EMAIL PROTECTED] Inviato: domenica 16 maggio 2004 11.58 A: Struts Users Mailing List Oggetto: Maintaining form data across pages... Dears, I am trying to setup a series of jsp pages (requestForm, confrimation jsp). I set the scope of my requestForm to "session" as to maintain the data across the various jsps, but I get it as if reset is called, after the confirmation page submits. What is the best way to maintain the request data across several jsp pages, speically I have lots of pages as step 1, step 2, step 3 before submiting the action, with different form beans. Thanks, best regards Ashraf Fouad - 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] - 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] - Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now
RE: Maintaining form data across pages...
Thanks very much, u have been of a great help :) -Original Message- From: Andrea M [mailto:[EMAIL PROTECTED] Sent: Sunday, May 16, 2004 2:06 PM To: 'Struts Users Mailing List' Subject: R: Maintaining form data across pages... Yes that's the way it works It does not matter in which scope the form is set 1. JSP submits the form 2. Struts goes to find one in the scope you told him 3. if it finds one, then it calls reset() (so to avoid having stale data), then populates it 4. it it doesn't find any form in the scope, then istantiates a new one then carries on This is because Struts doesn't know if the actionform it founds is being populated by a multiple-page form, or is simply a stale one. And this is why reset() takes httpServletRequest as parameter: so you can implement your own reset logic depending on your particular application flow -Messaggio originale- Da: ayouaa0a [mailto:[EMAIL PROTECTED] Inviato: domenica 16 maggio 2004 12.40 A: 'Struts Users Mailing List' Oggetto: RE: Maintaining form data across pages... Yes, that's what I want, I will give it a try. but what do u mean struts "always calls reset()" everytime it access the form, this is very strange, even the form is in session!! Plz domonstrate more, as far as I understood: 1- When a JSP submits a form. 2- Struts calls reset for the form. 3- Try to populate the form from the JSP controls, even it was in session. -Original Message- From: Andrea M [mailto:[EMAIL PROTECTED] Sent: Sunday, May 16, 2004 1:11 PM To: 'Struts Users Mailing List' Subject: R: Maintaining form data across pages... Hi I'm not sure I've understood properly what you need What I understand is that you are trying to populate the same actionform using several pages. The problem is that struts *always calls reset()* every time it access the form. What you can do is making your pages set a flag in the request, so your form can know where it's called from. Reset() method takes httpServletRequest as parameter, so you can implement conditional logic there... sometimes like: public void reset(ActionMapping mapping, HttpServletRequest request) { // first time accessed so I can set everything to null if (request.getParameter("flag") == null) { // set all properties to null here } else if (request.getParameter("flag").equals("page1") { // set to null only properties not present in page1 } else if (request.getParameter("flag").equals("page2") { // set to null only properties not present in page2 } ... } -Messaggio originale- Da: Ayoub, Ashraf A [mailto:[EMAIL PROTECTED] Inviato: domenica 16 maggio 2004 11.58 A: Struts Users Mailing List Oggetto: Maintaining form data across pages... Dears, I am trying to setup a series of jsp pages (requestForm, confrimation jsp). I set the scope of my requestForm to "session" as to maintain the data across the various jsps, but I get it as if reset is called, after the confirmation page submits. What is the best way to maintain the request data across several jsp pages, speically I have lots of pages as step 1, step 2, step 3 before submiting the action, with different form beans. Thanks, best regards Ashraf Fouad - 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] - 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: Maintaining form data across pages...
Ayoub, This was an issue that came across a little while ago, and I was surprised by the lack of existing solutions. What we did was to implement a little process engine wherein you could setup a single action (subclass of the process action) and setup within the action the steps (step1, step2, step3) etc. We then mapped inputs to the steps, so you would define a forward for each step which pointed to the view (jsp page) for that view. Another thing we did in our approach was to implement a pre-form mechanism which you can use to prepare information for each step view. I found the way struts deals (or doesn't) with view preparation a bit vague. Lukas -Original Message- From: Ayoub, Ashraf A [mailto:[EMAIL PROTECTED] Sent: Sunday, 16 May 2004 9:58 p.m. To: Struts Users Mailing List Subject: Maintaining form data across pages... Dears, I am trying to setup a series of jsp pages (requestForm, confrimation jsp). I set the scope of my requestForm to "session" as to maintain the data across the various jsps, but I get it as if reset is called, after the confirmation page submits. What is the best way to maintain the request data across several jsp pages, speically I have lots of pages as step 1, step 2, step 3 before submiting the action, with different form beans. Thanks, best regards Ashraf Fouad - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Maintaining form data across pages...
Ayoub, This was an issue that came across a little while ago, and I was surprised by the lack of existing solutions. What we did was to implement a little process engine wherein you could setup a single action (subclass of the process action) and setup within the action the steps (step1, step2, step3) etc. We then mapped inputs to the steps, so you would define a forward for each step which pointed to the view (jsp page) for that view. Another thing we did in our approach was to implement a pre-form mechanism which you can use to prepare information for each step view. I found the way struts deals (or doesn't) with view preparation a bit vague. Lukas -Original Message- From: Ayoub, Ashraf A [mailto:[EMAIL PROTECTED] Sent: Sunday, 16 May 2004 9:58 p.m. To: Struts Users Mailing List Subject: Maintaining form data across pages... Dears, I am trying to setup a series of jsp pages (requestForm, confrimation jsp). I set the scope of my requestForm to "session" as to maintain the data across the various jsps, but I get it as if reset is called, after the confirmation page submits. What is the best way to maintain the request data across several jsp pages, speically I have lots of pages as step 1, step 2, step 3 before submiting the action, with different form beans. Thanks, best regards Ashraf Fouad - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Maintaining form data across pages...
Yes, that's what I want, I will give it a try. but what do u mean struts "always calls reset()" everytime it access the form, this is very strange, even the form is in session!! Plz domonstrate more, as far as I understood: 1- When a JSP submits a form. 2- Struts calls reset for the form. 3- Try to populate the form from the JSP controls, even it was in session. -Original Message- From: Andrea M [mailto:[EMAIL PROTECTED] Sent: Sunday, May 16, 2004 1:11 PM To: 'Struts Users Mailing List' Subject: R: Maintaining form data across pages... Hi I'm not sure I've understood properly what you need What I understand is that you are trying to populate the same actionform using several pages. The problem is that struts *always calls reset()* every time it access the form. What you can do is making your pages set a flag in the request, so your form can know where it's called from. Reset() method takes httpServletRequest as parameter, so you can implement conditional logic there... sometimes like: public void reset(ActionMapping mapping, HttpServletRequest request) { // first time accessed so I can set everything to null if (request.getParameter("flag") == null) { // set all properties to null here } else if (request.getParameter("flag").equals("page1") { // set to null only properties not present in page1 } else if (request.getParameter("flag").equals("page2") { // set to null only properties not present in page2 } ... } -Messaggio originale- Da: Ayoub, Ashraf A [mailto:[EMAIL PROTECTED] Inviato: domenica 16 maggio 2004 11.58 A: Struts Users Mailing List Oggetto: Maintaining form data across pages... Dears, I am trying to setup a series of jsp pages (requestForm, confrimation jsp). I set the scope of my requestForm to "session" as to maintain the data across the various jsps, but I get it as if reset is called, after the confirmation page submits. What is the best way to maintain the request data across several jsp pages, speically I have lots of pages as step 1, step 2, step 3 before submiting the action, with different form beans. Thanks, best regards Ashraf Fouad - 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]