You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Hunter Hillegas <li...@lastonepicked.com> on 2003/04/24 01:19:58 UTC

Pre-Populating an ActionForm

I would like to pre-populate and ActionForm and I'm having trouble. I looked
through the list archives and couldn't find a scenario that seemed like
mine.

1. JSP page 1 submits to Struts Action (the form on this page is not managed
by Struts).
2. This Action looks up a customer record. I create a new instance of Form
A, use the setters to fill up the customer info, and then I add it to the
request scope:

request.setAttribute("sampleRequestBodyForm", theSampleRequestBodyForm);

3. We now end up on JSP page 2 via the ActionForward. The form on this page
is of type 'sampleRequestBodyForm'. Unfortunately, none of the fields I used
setters on have any data in them...

So, I assume I am using the wrong attribute name or something... What is the
attribute name I should be using?

Thanks,
hunter


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Pre-Populating an ActionForm

Posted by Phil Steitz <ph...@steitz.com>.
Hunter Hillegas wrote:
> The form that is on the page that comes after the submission to the struts
> action *is* managed by Struts.
> 
What I meant was to have struts instantiate the form and put in into the 
request automatically for you by declaring it in the action definition 
in step 2.  Your "pre-populate" action should declare a form bean, which 
struts create for you.  Struts will also put it into the request so that 
  its properties can be linked to HTML elements on your jsp page 2. 
That is how the EditRegistration in the sample app (described in the FAQ 
below) works.

> 
>>From: Micael <ca...@harbornet.com>
>>Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>>Date: Wed, 23 Apr 2003 21:39:55 -0700
>>To: "Struts Users Mailing List" <st...@jakarta.apache.org>, "Struts
>>Users Mailing List" <st...@jakarta.apache.org>, "Struts Users Mailing
>>List" <st...@jakarta.apache.org>
>>Subject: Re: Pre-Populating an ActionForm
>>
>>Hunter, why would a page with a form submit to a struts action when the
>>form on the page is not managed by struts?  I don't really understand
>>that.  The form would be completely otiose then?
>>
>>Micael
>>
>>At 08:45 PM 4/23/03 -0700, Micael wrote:
>>
>>>The obvious reason is that none of the values in that form are set.  This
>>>has to be because either they were never set, or they were reset after
>>>being set.  There is not enough detail in your question to tell what is
>>>going on.  I assume something like the following is going on:
>>>
>>>You have someone enter their name?  They are a customer?  You want this to
>>>result in a form showing up prepopulated with all their information on the
>>>form?  I would suggest the following:
>>>
>>>Have the action create a bean representing the customer and put that in
>>>the session the customer is using.  When the action returns to the form,
>>>populate fhe fields with the values of the bean?  Not sure why you are
>>>using the form the way you are.  You should, I think, keep the view
>>>separate from your business logic.
>>>
>>>Make sense?
>>>
>>>Micael
>>>
>>>At 08:11 PM 4/23/03 -0700, Phil Steitz wrote:
>>>
>>>>Hunter Hillegas wrote:
>>>>
>>>>>I would like to pre-populate and ActionForm and I'm having trouble. I
>>>>>looked
>>>>>through the list archives and couldn't find a scenario that seemed like
>>>>>mine.
>>>>>1. JSP page 1 submits to Struts Action (the form on this page is not
>>>>>managed
>>>>>by Struts).
>>>>>2. This Action looks up a customer record. I create a new instance of Form
>>>>>A, use the setters to fill up the customer info, and then I add it to the
>>>>>request scope:
>>>>>request.setAttribute("sampleRequestBodyForm", theSampleRequestBodyForm);
>>>>>3. We now end up on JSP page 2 via the ActionForward. The form on this page
>>>>>is of type 'sampleRequestBodyForm'. Unfortunately, none of the fields I
>>>>>used
>>>>>setters on have any data in them...
>>>>>So, I assume I am using the wrong attribute name or something... What is
>>>>>the
>>>>>attribute name I should be using?
>>>>>Thanks,
>>>>>hunter
>>>>
>>>>You shoould let the framework manage the action form in step 2.  See
>>>>http://jakarta.apache.org/struts/faqs/newbie.html#prepopulate
>>>>
>>>>
>>>>>---------------------------------------------------------------------
>>>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>>
>>>
>>>LEGAL NOTICE
>>>
>>>This electronic mail  transmission and any accompanying documents contain
>>>information belonging to the sender which may be confidential and legally
>>>privileged.  This information is intended only for the use of the
>>>individual or entity to whom this electronic mail transmission was sent as
>>>indicated above. If you are not the intended recipient, any disclosure,
>>>copying, distribution, or action taken in reliance on the contents of the
>>>information contained in this transmission is strictly prohibited.  If you
>>>have received this transmission in error, please delete the
>>>message.  Thank you
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>
>>
>>
>>LEGAL NOTICE
>>
>>This electronic mail  transmission and any accompanying documents contain
>>information belonging to the sender which may be confidential and legally
>>privileged.  This information is intended only for the use of the
>>individual or entity to whom this electronic mail transmission was sent as
>>indicated above. If you are not the intended recipient, any disclosure,
>>copying, distribution, or action taken in reliance on the contents of the
>>information contained in this transmission is strictly prohibited.  If you
>>have received this transmission in error, please delete the message.  Thank
>>you  
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 

r


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Pre-Populating an ActionForm

Posted by Hunter Hillegas <li...@lastonepicked.com>.
The form that is on the page that comes after the submission to the struts
action *is* managed by Struts.

> From: Micael <ca...@harbornet.com>
> Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Date: Wed, 23 Apr 2003 21:39:55 -0700
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>, "Struts
> Users Mailing List" <st...@jakarta.apache.org>, "Struts Users Mailing
> List" <st...@jakarta.apache.org>
> Subject: Re: Pre-Populating an ActionForm
> 
> Hunter, why would a page with a form submit to a struts action when the
> form on the page is not managed by struts?  I don't really understand
> that.  The form would be completely otiose then?
> 
> Micael
> 
> At 08:45 PM 4/23/03 -0700, Micael wrote:
>> The obvious reason is that none of the values in that form are set.  This
>> has to be because either they were never set, or they were reset after
>> being set.  There is not enough detail in your question to tell what is
>> going on.  I assume something like the following is going on:
>> 
>> You have someone enter their name?  They are a customer?  You want this to
>> result in a form showing up prepopulated with all their information on the
>> form?  I would suggest the following:
>> 
>> Have the action create a bean representing the customer and put that in
>> the session the customer is using.  When the action returns to the form,
>> populate fhe fields with the values of the bean?  Not sure why you are
>> using the form the way you are.  You should, I think, keep the view
>> separate from your business logic.
>> 
>> Make sense?
>> 
>> Micael
>> 
>> At 08:11 PM 4/23/03 -0700, Phil Steitz wrote:
>>> Hunter Hillegas wrote:
>>>> I would like to pre-populate and ActionForm and I'm having trouble. I
>>>> looked
>>>> through the list archives and couldn't find a scenario that seemed like
>>>> mine.
>>>> 1. JSP page 1 submits to Struts Action (the form on this page is not
>>>> managed
>>>> by Struts).
>>>> 2. This Action looks up a customer record. I create a new instance of Form
>>>> A, use the setters to fill up the customer info, and then I add it to the
>>>> request scope:
>>>> request.setAttribute("sampleRequestBodyForm", theSampleRequestBodyForm);
>>>> 3. We now end up on JSP page 2 via the ActionForward. The form on this page
>>>> is of type 'sampleRequestBodyForm'. Unfortunately, none of the fields I
>>>> used
>>>> setters on have any data in them...
>>>> So, I assume I am using the wrong attribute name or something... What is
>>>> the
>>>> attribute name I should be using?
>>>> Thanks,
>>>> hunter
>>> 
>>> You shoould let the framework manage the action form in step 2.  See
>>> http://jakarta.apache.org/struts/faqs/newbie.html#prepopulate
>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>> 
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>> 
>> 
>> 
>> LEGAL NOTICE
>> 
>> This electronic mail  transmission and any accompanying documents contain
>> information belonging to the sender which may be confidential and legally
>> privileged.  This information is intended only for the use of the
>> individual or entity to whom this electronic mail transmission was sent as
>> indicated above. If you are not the intended recipient, any disclosure,
>> copying, distribution, or action taken in reliance on the contents of the
>> information contained in this transmission is strictly prohibited.  If you
>> have received this transmission in error, please delete the
>> message.  Thank you
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>> 
> 
> 
> 
> LEGAL NOTICE
> 
> This electronic mail  transmission and any accompanying documents contain
> information belonging to the sender which may be confidential and legally
> privileged.  This information is intended only for the use of the
> individual or entity to whom this electronic mail transmission was sent as
> indicated above. If you are not the intended recipient, any disclosure,
> copying, distribution, or action taken in reliance on the contents of the
> information contained in this transmission is strictly prohibited.  If you
> have received this transmission in error, please delete the message.  Thank
> you  
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Pre-Populating an ActionForm

Posted by Micael <ca...@harbornet.com>.
Hunter, why would a page with a form submit to a struts action when the 
form on the page is not managed by struts?  I don't really understand 
that.  The form would be completely otiose then?

Micael

At 08:45 PM 4/23/03 -0700, Micael wrote:
>The obvious reason is that none of the values in that form are set.  This 
>has to be because either they were never set, or they were reset after 
>being set.  There is not enough detail in your question to tell what is 
>going on.  I assume something like the following is going on:
>
>You have someone enter their name?  They are a customer?  You want this to 
>result in a form showing up prepopulated with all their information on the 
>form?  I would suggest the following:
>
>Have the action create a bean representing the customer and put that in 
>the session the customer is using.  When the action returns to the form, 
>populate fhe fields with the values of the bean?  Not sure why you are 
>using the form the way you are.  You should, I think, keep the view 
>separate from your business logic.
>
>Make sense?
>
>Micael
>
>At 08:11 PM 4/23/03 -0700, Phil Steitz wrote:
>>Hunter Hillegas wrote:
>>>I would like to pre-populate and ActionForm and I'm having trouble. I looked
>>>through the list archives and couldn't find a scenario that seemed like
>>>mine.
>>>1. JSP page 1 submits to Struts Action (the form on this page is not managed
>>>by Struts).
>>>2. This Action looks up a customer record. I create a new instance of Form
>>>A, use the setters to fill up the customer info, and then I add it to the
>>>request scope:
>>>request.setAttribute("sampleRequestBodyForm", theSampleRequestBodyForm);
>>>3. We now end up on JSP page 2 via the ActionForward. The form on this page
>>>is of type 'sampleRequestBodyForm'. Unfortunately, none of the fields I used
>>>setters on have any data in them...
>>>So, I assume I am using the wrong attribute name or something... What is the
>>>attribute name I should be using?
>>>Thanks,
>>>hunter
>>
>>You shoould let the framework manage the action form in step 2.  See 
>>http://jakarta.apache.org/struts/faqs/newbie.html#prepopulate
>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>LEGAL NOTICE
>
>This electronic mail  transmission and any accompanying documents contain 
>information belonging to the sender which may be confidential and legally 
>privileged.  This information is intended only for the use of the 
>individual or entity to whom this electronic mail transmission was sent as 
>indicated above. If you are not the intended recipient, any disclosure, 
>copying, distribution, or action taken in reliance on the contents of the 
>information contained in this transmission is strictly prohibited.  If you 
>have received this transmission in error, please delete the 
>message.  Thank you
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>



LEGAL NOTICE

This electronic mail  transmission and any accompanying documents contain 
information belonging to the sender which may be confidential and legally 
privileged.  This information is intended only for the use of the 
individual or entity to whom this electronic mail transmission was sent as 
indicated above. If you are not the intended recipient, any disclosure, 
copying, distribution, or action taken in reliance on the contents of the 
information contained in this transmission is strictly prohibited.  If you 
have received this transmission in error, please delete the message.  Thank 
you  



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Pre-Populating an ActionForm

Posted by Robert Taylor <rt...@mulework.com>.
If it is a forward and not a redirect, then the
"request context object" is not destroyed but merely
propogated.

robert

> -----Original Message-----
> From: Micael [mailto:caraunltd@harbornet.com]
> Sent: Thursday, April 24, 2003 11:37 AM
> To: Struts Users Mailing List
> Subject: Re: Pre-Populating an ActionForm
>
>
> Whatever you populate the form with has to survive past the life-cycle of
> the previous request context object.  At least that much is true.
>
> At 09:57 PM 4/23/03 -0700, you wrote:
> >So the key is to put it in the session and not the request scope?
> >
> >Basically I want to pre-fill a form with some info based on what
> selection a
> >user makes from a drop-down list in the first form.
> >
> > > From: Micael <ca...@harbornet.com>
> > > Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > > Date: Wed, 23 Apr 2003 20:45:46 -0700
> > > To: "Struts Users Mailing List"
> <st...@jakarta.apache.org>, "Struts
> > > Users Mailing List" <st...@jakarta.apache.org>
> > > Subject: Re: Pre-Populating an ActionForm
> > >
> > > The obvious reason is that none of the values in that form
> are set.  This
> > > has to be because either they were never set, or they were reset after
> > > being set.  There is not enough detail in your question to
> tell what is
> > > going on.  I assume something like the following is going on:
> > >
> > > You have someone enter their name?  They are a customer?  You
> want this to
> > > result in a form showing up prepopulated with all their
> information on the
> > > form?  I would suggest the following:
> > >
> > > Have the action create a bean representing the customer and
> put that in the
> > > session the customer is using.  When the action returns to the form,
> > > populate fhe fields with the values of the bean?  Not sure why you are
> > > using the form the way you are.  You should, I think, keep the view
> > > separate from your business logic.
> > >
> > > Make sense?
> > >
> > > Micael
> > >
> > > At 08:11 PM 4/23/03 -0700, Phil Steitz wrote:
> > >> Hunter Hillegas wrote:
> > >>> I would like to pre-populate and ActionForm and I'm having
> trouble. I
> > looked
> > >>> through the list archives and couldn't find a scenario that
> seemed like
> > >>> mine.
> > >>> 1. JSP page 1 submits to Struts Action (the form on this
> page is not
> > managed
> > >>> by Struts).
> > >>> 2. This Action looks up a customer record. I create a new
> instance of
> > Form
> > >>> A, use the setters to fill up the customer info, and then I
> add it to the
> > >>> request scope:
> > >>> request.setAttribute("sampleRequestBodyForm",
> theSampleRequestBodyForm);
> > >>> 3. We now end up on JSP page 2 via the ActionForward. The form on
> > this page
> > >>> is of type 'sampleRequestBodyForm'. Unfortunately, none of
> the fields
> > I used
> > >>> setters on have any data in them...
> > >>> So, I assume I am using the wrong attribute name or
> something... What
> > is the
> > >>> attribute name I should be using?
> > >>> Thanks,
> > >>> hunter
> > >>
> > >> You shoould let the framework manage the action form in step 2.  See
> > >> http://jakarta.apache.org/struts/faqs/newbie.html#prepopulate
> > >>
> > >>>
> ---------------------------------------------------------------------
> > >>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > >>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >>
> > >>
> > >>
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > >> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >>
> > >
> > >
> > >
> > > LEGAL NOTICE
> > >
> > > This electronic mail  transmission and any accompanying
> documents contain
> > > information belonging to the sender which may be confidential
> and legally
> > > privileged.  This information is intended only for the use of the
> > > individual or entity to whom this electronic mail
> transmission was sent as
> > > indicated above. If you are not the intended recipient, any
> disclosure,
> > > copying, distribution, or action taken in reliance on the
> contents of the
> > > information contained in this transmission is strictly
> prohibited.  If you
> > > have received this transmission in error, please delete the
> message.  Thank
> > > you
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
> LEGAL NOTICE
>
> This electronic mail  transmission and any accompanying documents contain
> information belonging to the sender which may be confidential and legally
> privileged.  This information is intended only for the use of the
> individual or entity to whom this electronic mail transmission
> was sent as
> indicated above. If you are not the intended recipient, any disclosure,
> copying, distribution, or action taken in reliance on the contents of the
> information contained in this transmission is strictly
> prohibited.  If you
> have received this transmission in error, please delete the
> message.  Thank
> you
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Pre-Populating an ActionForm

Posted by Hunter Hillegas <li...@lastonepicked.com>.
Yeah, that makes good sense.

I got a lot of good feedback that I am going to read through and then I'll
test some things out.

Thank you all for your help.

> From: Micael <ca...@harbornet.com>
> Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Date: Thu, 24 Apr 2003 08:36:53 -0700
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Subject: Re: Pre-Populating an ActionForm
> 
> Whatever you populate the form with has to survive past the life-cycle of
> the previous request context object.  At least that much is true.
> 
> At 09:57 PM 4/23/03 -0700, you wrote:
>> So the key is to put it in the session and not the request scope?
>> 
>> Basically I want to pre-fill a form with some info based on what selection a
>> user makes from a drop-down list in the first form.
>> 
>>> From: Micael <ca...@harbornet.com>
>>> Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>>> Date: Wed, 23 Apr 2003 20:45:46 -0700
>>> To: "Struts Users Mailing List" <st...@jakarta.apache.org>, "Struts
>>> Users Mailing List" <st...@jakarta.apache.org>
>>> Subject: Re: Pre-Populating an ActionForm
>>> 
>>> The obvious reason is that none of the values in that form are set.  This
>>> has to be because either they were never set, or they were reset after
>>> being set.  There is not enough detail in your question to tell what is
>>> going on.  I assume something like the following is going on:
>>> 
>>> You have someone enter their name?  They are a customer?  You want this to
>>> result in a form showing up prepopulated with all their information on the
>>> form?  I would suggest the following:
>>> 
>>> Have the action create a bean representing the customer and put that in the
>>> session the customer is using.  When the action returns to the form,
>>> populate fhe fields with the values of the bean?  Not sure why you are
>>> using the form the way you are.  You should, I think, keep the view
>>> separate from your business logic.
>>> 
>>> Make sense?
>>> 
>>> Micael
>>> 
>>> At 08:11 PM 4/23/03 -0700, Phil Steitz wrote:
>>>> Hunter Hillegas wrote:
>>>>> I would like to pre-populate and ActionForm and I'm having trouble. I
>> looked
>>>>> through the list archives and couldn't find a scenario that seemed like
>>>>> mine.
>>>>> 1. JSP page 1 submits to Struts Action (the form on this page is not
>> managed
>>>>> by Struts).
>>>>> 2. This Action looks up a customer record. I create a new instance of
>> Form
>>>>> A, use the setters to fill up the customer info, and then I add it to the
>>>>> request scope:
>>>>> request.setAttribute("sampleRequestBodyForm", theSampleRequestBodyForm);
>>>>> 3. We now end up on JSP page 2 via the ActionForward. The form on
>> this page
>>>>> is of type 'sampleRequestBodyForm'. Unfortunately, none of the fields
>> I used
>>>>> setters on have any data in them...
>>>>> So, I assume I am using the wrong attribute name or something... What
>> is the
>>>>> attribute name I should be using?
>>>>> Thanks,
>>>>> hunter
>>>> 
>>>> You shoould let the framework manage the action form in step 2.  See
>>>> http://jakarta.apache.org/struts/faqs/newbie.html#prepopulate
>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>> 
>>>> 
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>> 
>>> 
>>> 
>>> 
>>> LEGAL NOTICE
>>> 
>>> This electronic mail  transmission and any accompanying documents contain
>>> information belonging to the sender which may be confidential and legally
>>> privileged.  This information is intended only for the use of the
>>> individual or entity to whom this electronic mail transmission was sent as
>>> indicated above. If you are not the intended recipient, any disclosure,
>>> copying, distribution, or action taken in reliance on the contents of the
>>> information contained in this transmission is strictly prohibited.  If you
>>> have received this transmission in error, please delete the message.  Thank
>>> you
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 
> 
> LEGAL NOTICE
> 
> This electronic mail  transmission and any accompanying documents contain
> information belonging to the sender which may be confidential and legally
> privileged.  This information is intended only for the use of the
> individual or entity to whom this electronic mail transmission was sent as
> indicated above. If you are not the intended recipient, any disclosure,
> copying, distribution, or action taken in reliance on the contents of the
> information contained in this transmission is strictly prohibited.  If you
> have received this transmission in error, please delete the message.  Thank
> you  
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Pre-Populating an ActionForm

Posted by Micael <ca...@harbornet.com>.
Whatever you populate the form with has to survive past the life-cycle of 
the previous request context object.  At least that much is true.

At 09:57 PM 4/23/03 -0700, you wrote:
>So the key is to put it in the session and not the request scope?
>
>Basically I want to pre-fill a form with some info based on what selection a
>user makes from a drop-down list in the first form.
>
> > From: Micael <ca...@harbornet.com>
> > Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > Date: Wed, 23 Apr 2003 20:45:46 -0700
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>, "Struts
> > Users Mailing List" <st...@jakarta.apache.org>
> > Subject: Re: Pre-Populating an ActionForm
> >
> > The obvious reason is that none of the values in that form are set.  This
> > has to be because either they were never set, or they were reset after
> > being set.  There is not enough detail in your question to tell what is
> > going on.  I assume something like the following is going on:
> >
> > You have someone enter their name?  They are a customer?  You want this to
> > result in a form showing up prepopulated with all their information on the
> > form?  I would suggest the following:
> >
> > Have the action create a bean representing the customer and put that in the
> > session the customer is using.  When the action returns to the form,
> > populate fhe fields with the values of the bean?  Not sure why you are
> > using the form the way you are.  You should, I think, keep the view
> > separate from your business logic.
> >
> > Make sense?
> >
> > Micael
> >
> > At 08:11 PM 4/23/03 -0700, Phil Steitz wrote:
> >> Hunter Hillegas wrote:
> >>> I would like to pre-populate and ActionForm and I'm having trouble. I 
> looked
> >>> through the list archives and couldn't find a scenario that seemed like
> >>> mine.
> >>> 1. JSP page 1 submits to Struts Action (the form on this page is not 
> managed
> >>> by Struts).
> >>> 2. This Action looks up a customer record. I create a new instance of 
> Form
> >>> A, use the setters to fill up the customer info, and then I add it to the
> >>> request scope:
> >>> request.setAttribute("sampleRequestBodyForm", theSampleRequestBodyForm);
> >>> 3. We now end up on JSP page 2 via the ActionForward. The form on 
> this page
> >>> is of type 'sampleRequestBodyForm'. Unfortunately, none of the fields 
> I used
> >>> setters on have any data in them...
> >>> So, I assume I am using the wrong attribute name or something... What 
> is the
> >>> attribute name I should be using?
> >>> Thanks,
> >>> hunter
> >>
> >> You shoould let the framework manage the action form in step 2.  See
> >> http://jakarta.apache.org/struts/faqs/newbie.html#prepopulate
> >>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>
> >
> >
> >
> > LEGAL NOTICE
> >
> > This electronic mail  transmission and any accompanying documents contain
> > information belonging to the sender which may be confidential and legally
> > privileged.  This information is intended only for the use of the
> > individual or entity to whom this electronic mail transmission was sent as
> > indicated above. If you are not the intended recipient, any disclosure,
> > copying, distribution, or action taken in reliance on the contents of the
> > information contained in this transmission is strictly prohibited.  If you
> > have received this transmission in error, please delete the message.  Thank
> > you
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org



LEGAL NOTICE

This electronic mail  transmission and any accompanying documents contain 
information belonging to the sender which may be confidential and legally 
privileged.  This information is intended only for the use of the 
individual or entity to whom this electronic mail transmission was sent as 
indicated above. If you are not the intended recipient, any disclosure, 
copying, distribution, or action taken in reliance on the contents of the 
information contained in this transmission is strictly prohibited.  If you 
have received this transmission in error, please delete the message.  Thank 
you  



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Pre-Populating an ActionForm

Posted by Hunter Hillegas <li...@lastonepicked.com>.
So the key is to put it in the session and not the request scope?

Basically I want to pre-fill a form with some info based on what selection a
user makes from a drop-down list in the first form.

> From: Micael <ca...@harbornet.com>
> Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Date: Wed, 23 Apr 2003 20:45:46 -0700
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>, "Struts
> Users Mailing List" <st...@jakarta.apache.org>
> Subject: Re: Pre-Populating an ActionForm
> 
> The obvious reason is that none of the values in that form are set.  This
> has to be because either they were never set, or they were reset after
> being set.  There is not enough detail in your question to tell what is
> going on.  I assume something like the following is going on:
> 
> You have someone enter their name?  They are a customer?  You want this to
> result in a form showing up prepopulated with all their information on the
> form?  I would suggest the following:
> 
> Have the action create a bean representing the customer and put that in the
> session the customer is using.  When the action returns to the form,
> populate fhe fields with the values of the bean?  Not sure why you are
> using the form the way you are.  You should, I think, keep the view
> separate from your business logic.
> 
> Make sense?
> 
> Micael
> 
> At 08:11 PM 4/23/03 -0700, Phil Steitz wrote:
>> Hunter Hillegas wrote:
>>> I would like to pre-populate and ActionForm and I'm having trouble. I looked
>>> through the list archives and couldn't find a scenario that seemed like
>>> mine.
>>> 1. JSP page 1 submits to Struts Action (the form on this page is not managed
>>> by Struts).
>>> 2. This Action looks up a customer record. I create a new instance of Form
>>> A, use the setters to fill up the customer info, and then I add it to the
>>> request scope:
>>> request.setAttribute("sampleRequestBodyForm", theSampleRequestBodyForm);
>>> 3. We now end up on JSP page 2 via the ActionForward. The form on this page
>>> is of type 'sampleRequestBodyForm'. Unfortunately, none of the fields I used
>>> setters on have any data in them...
>>> So, I assume I am using the wrong attribute name or something... What is the
>>> attribute name I should be using?
>>> Thanks,
>>> hunter
>> 
>> You shoould let the framework manage the action form in step 2.  See
>> http://jakarta.apache.org/struts/faqs/newbie.html#prepopulate
>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>> 
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>> 
> 
> 
> 
> LEGAL NOTICE
> 
> This electronic mail  transmission and any accompanying documents contain
> information belonging to the sender which may be confidential and legally
> privileged.  This information is intended only for the use of the
> individual or entity to whom this electronic mail transmission was sent as
> indicated above. If you are not the intended recipient, any disclosure,
> copying, distribution, or action taken in reliance on the contents of the
> information contained in this transmission is strictly prohibited.  If you
> have received this transmission in error, please delete the message.  Thank
> you  
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Pre-Populating an ActionForm

Posted by Micael <ca...@harbornet.com>.
The obvious reason is that none of the values in that form are set.  This 
has to be because either they were never set, or they were reset after 
being set.  There is not enough detail in your question to tell what is 
going on.  I assume something like the following is going on:

You have someone enter their name?  They are a customer?  You want this to 
result in a form showing up prepopulated with all their information on the 
form?  I would suggest the following:

Have the action create a bean representing the customer and put that in the 
session the customer is using.  When the action returns to the form, 
populate fhe fields with the values of the bean?  Not sure why you are 
using the form the way you are.  You should, I think, keep the view 
separate from your business logic.

Make sense?

Micael

At 08:11 PM 4/23/03 -0700, Phil Steitz wrote:
>Hunter Hillegas wrote:
>>I would like to pre-populate and ActionForm and I'm having trouble. I looked
>>through the list archives and couldn't find a scenario that seemed like
>>mine.
>>1. JSP page 1 submits to Struts Action (the form on this page is not managed
>>by Struts).
>>2. This Action looks up a customer record. I create a new instance of Form
>>A, use the setters to fill up the customer info, and then I add it to the
>>request scope:
>>request.setAttribute("sampleRequestBodyForm", theSampleRequestBodyForm);
>>3. We now end up on JSP page 2 via the ActionForward. The form on this page
>>is of type 'sampleRequestBodyForm'. Unfortunately, none of the fields I used
>>setters on have any data in them...
>>So, I assume I am using the wrong attribute name or something... What is the
>>attribute name I should be using?
>>Thanks,
>>hunter
>
>You shoould let the framework manage the action form in step 2.  See 
>http://jakarta.apache.org/struts/faqs/newbie.html#prepopulate
>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>



LEGAL NOTICE

This electronic mail  transmission and any accompanying documents contain 
information belonging to the sender which may be confidential and legally 
privileged.  This information is intended only for the use of the 
individual or entity to whom this electronic mail transmission was sent as 
indicated above. If you are not the intended recipient, any disclosure, 
copying, distribution, or action taken in reliance on the contents of the 
information contained in this transmission is strictly prohibited.  If you 
have received this transmission in error, please delete the message.  Thank 
you  



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Pre-Populating an ActionForm

Posted by Phil Steitz <ph...@steitz.com>.
Hunter Hillegas wrote:
> I would like to pre-populate and ActionForm and I'm having trouble. I looked
> through the list archives and couldn't find a scenario that seemed like
> mine.
> 
> 1. JSP page 1 submits to Struts Action (the form on this page is not managed
> by Struts).
> 2. This Action looks up a customer record. I create a new instance of Form
> A, use the setters to fill up the customer info, and then I add it to the
> request scope:
> 
> request.setAttribute("sampleRequestBodyForm", theSampleRequestBodyForm);
> 
> 3. We now end up on JSP page 2 via the ActionForward. The form on this page
> is of type 'sampleRequestBodyForm'. Unfortunately, none of the fields I used
> setters on have any data in them...
> 
> So, I assume I am using the wrong attribute name or something... What is the
> attribute name I should be using?
> 
> Thanks,
> hunter
> 

You shoould let the framework manage the action form in step 2.  See 
http://jakarta.apache.org/struts/faqs/newbie.html#prepopulate

> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Pre-Populating an ActionForm

Posted by Robert Taylor <rt...@mulework.com>.
Hunter,

I think I understand, but let me recap, just so we are on the same page:

1. JSP page 1 submits to ActionA

2. ActionA handles request
   2.1 captures data
   2.2 retrieves customer record
   2.3 instantiates FormA
   2.4 populates FormA with customer record
   2.5 places FormA in request scope as "sampleRequestBodyForm"
   2.6 forwards to JSP page 2

3. JSP page 2 contains a form with an action which is associated
   with the form "sampleRequestBodyForm".

4. JSP page 2 is displayed but "sampleRequestBodyForm" is empty



Suggestions:

- Associate sampleRequestBodyForm with ActionA and set the
  scope to "request". By doing this, sampleRequestBodyForm
  will already exist in request scope and will be passed to
  ActionA. By doing this, you can eliminate steps 2.3 and 2.5.
  (I think this is what Phil was alluding to)

- Make sure that the form on JSP page 2 has an action which
  is associated to sampleRequestBodyForm in request scope.

- I this pattern quite often, and therefore don't see a need
  to put your form in session scope. In general, it's considered
  a best practice to keep session scope sparse.

Just to clarify my suggestion:

1. JSP page 1 submits to ActionA
2. Since "sampleRequestBodyForm" is associated with ActionA
   and is defined to be in request scope, Struts will instantiate
   FormA as "sampleRequestBodyForm" and place it in request scope.
3. ActionA handles request
   3.1 ActionA accesses the instance of FormA
   3.2 ActionA (or some business delegate ) retrieves customer
       information
   3.3 ActionA (or some helper) populates FormA
   3.4 ActionA forwards to logical success (JSP page 2)
4. JSP page 2 contains an <html:form .../> whose action attribute
   value is an Action which is associated with form "sampleRequestBodyForm"
   in request scope.
5. <html:form .../> finds "sampleRequestBodyForm" in request scope, and
   renders its contents to the screen.

If, this is indeed what you are doing, then yes, check your attribute names
and
make sure they all correspond correctly.


HTH,

robert



> -----Original Message-----
> From: Hunter Hillegas [mailto:lists@lastonepicked.com]
> Sent: Wednesday, April 23, 2003 7:20 PM
> To: Struts List
> Subject: Pre-Populating an ActionForm
>
>
> I would like to pre-populate and ActionForm and I'm having
> trouble. I looked
> through the list archives and couldn't find a scenario that seemed like
> mine.
>
> 1. JSP page 1 submits to Struts Action (the form on this page is
> not managed
> by Struts).
> 2. This Action looks up a customer record. I create a new instance of Form
> A, use the setters to fill up the customer info, and then I add it to the
> request scope:
>
> request.setAttribute("sampleRequestBodyForm", theSampleRequestBodyForm);
>
> 3. We now end up on JSP page 2 via the ActionForward. The form on
> this page
> is of type 'sampleRequestBodyForm'. Unfortunately, none of the
> fields I used
> setters on have any data in them...
>
> So, I assume I am using the wrong attribute name or something...
> What is the
> attribute name I should be using?
>
> Thanks,
> hunter
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org