You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Antony Stace <s4...@yahoo.com> on 2002/02/01 08:07:11 UTC
Are Vectors in a FormAction set to null after a user has submitted a form?
Hi
I have several variables of type
Vector
in a FormAction. This form is used on a page where a user can input data, the contents of the Vectors are used to
populate drop down list boxes and were populated before the page was displayed to the user. After the user has
submitted this form I look at the form and pull the variables
out which the user has entered. I also want to be able to use the Vectors which were in the form previously. However
these Vectors are null, is this correct behaviour of struts? If not, how can I get the contents of these Vectors
--
Cheers
Tony
---------------------------------------------------------------------
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Are Vectors in a FormAction set to null after a user has submitted a form?
Posted by Keith Bacon <ke...@yahoo.com>.
It will indeed be called.
Ted posted advice on how to deal with this a few weeks ago - try to find it in the archives.
Basically reset() needs to know which form was submitted so it can reset only the fields on it.
Keith.
--- Antony Stace <s4...@yahoo.com> wrote:
> Hi Rick
>
> Thank you very much for the reply.
>
> On Thu, 07 Feb 2002 13:17:45 -0700
> Rick Holland <f1...@cosd.fedex.com> wrote:
>
> > Did you know that the ControllerServlet calls reset on a form before
> > populating it
> > from the request? If your form reset method clears the instvars it may
> > be the problem.
>
> If this is the case, does this mean that any form which is set to session scope in the
> struts-config.xml
> file will have its reset() method called each time it is used by an action?Ie, If I have
>
> <action path="/test1"
> type="TestAction"
> scope="session"
> name="messageForm"
> parameter="add"
> </action>
> <action path="/test2"
> type="TestAction"
> scope="session"
> name="messageForm"
> parameter="del"
> </action>
>
> And /test1 is called, the user enters data into the form and the data is saved in the
> messageForm bean which is saved. Later, the user
> calls /test2, will the reset method in messageForm be called?
>
>
> Cheers
>
> Tony
>
>
>
>
>
> >
> > Antony Stace wrote:
> >
> > >Hi Chuck
> > >
> > >I just tried having the first actions scope set to scope="session" and the second actions
> scope set to scope="session"
> > >and still the Vector data is still disapearing. I actually, for a test, set another field in
> ActionForm in the first action to a
> > >test value, I didn't have this set on the form anywhere where the user could change this
> value, then in the
> > >second action I tried to access this data, but it was not there - it too was gone. Somehow a
> new form is being created
> > >and the scope="session" is not happening.
> > >Any ideas anyone?
> > >
> > >Cheers
> > >
> > >Tony
> > >
> > >
> > >On Fri, 01 Feb 2002 07:51:12 -0500
> > >Chuck Cavaness <st...@japache.org> wrote:
> > >
> > >>That's sort of what I was saying. In the second action, the one that is called after the
> user sees the form data and makes some choices, does the scope equal to request or session? If
> you have both of these actions defined as session scope, then I don't believe a new ActionForm
> would be created during the second action. If the mapping is session, then an ActionForm will be
> looked for in the session, which should have been put there on the previous action (along with
> the Vector data in it still).
> > >>
> > >>However, if the second action is defined as request and the first one is session, then yes
> the user entered data would make it to the new ActionForm and the Vector data would be gone
> because one would be recycled.
> > >>
> > >>Obviously, this is all a guess. I hope it helps somehow.
> > >>
> > >>Chuck
> > >>--
> > >>Sent via jApache.org
> > >>
> > >>--
> > >>To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> > >>For additional commands, e-mail: <ma...@jakarta.apache.org>
> > >>
> > >
> > >
> >
> > --
> >
> > ------------------------------------------------------------------
> > - Rick Holland OO/Distributed Systems Consultant
> > - ObjectAge Inc.
> > - rgholland1@fedex.com
> > "Logic is a wreath of pretty flowers, that smell bad"
> > ------------------------------------------------------------------
> >
> >
> >
>
>
> --
>
>
> Cheers
>
> Tony��
> ---------------------------------------------------------------------
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Are Vectors in a FormAction set to null after a user has submitted a form?
Posted by Antony Stace <s4...@yahoo.com>.
Hi Rick
Thank you very much for the reply.
On Thu, 07 Feb 2002 13:17:45 -0700
Rick Holland <f1...@cosd.fedex.com> wrote:
> Did you know that the ControllerServlet calls reset on a form before
> populating it
> from the request? If your form reset method clears the instvars it may
> be the problem.
If this is the case, does this mean that any form which is set to session scope in the struts-config.xml
file will have its reset() method called each time it is used by an action?Ie, If I have
<action path="/test1"
type="TestAction"
scope="session"
name="messageForm"
parameter="add"
</action>
<action path="/test2"
type="TestAction"
scope="session"
name="messageForm"
parameter="del"
</action>
And /test1 is called, the user enters data into the form and the data is saved in the messageForm bean which is saved. Later, the user
calls /test2, will the reset method in messageForm be called?
Cheers
Tony
>
> Antony Stace wrote:
>
> >Hi Chuck
> >
> >I just tried having the first actions scope set to scope="session" and the second actions scope set to scope="session"
> >and still the Vector data is still disapearing. I actually, for a test, set another field in ActionForm in the first action to a
> >test value, I didn't have this set on the form anywhere where the user could change this value, then in the
> >second action I tried to access this data, but it was not there - it too was gone. Somehow a new form is being created
> >and the scope="session" is not happening.
> >Any ideas anyone?
> >
> >Cheers
> >
> >Tony
> >
> >
> >On Fri, 01 Feb 2002 07:51:12 -0500
> >Chuck Cavaness <st...@japache.org> wrote:
> >
> >>That's sort of what I was saying. In the second action, the one that is called after the user sees the form data and makes some choices, does the scope equal to request or session? If you have both of these actions defined as session scope, then I don't believe a new ActionForm would be created during the second action. If the mapping is session, then an ActionForm will be looked for in the session, which should have been put there on the previous action (along with the Vector data in it still).
> >>
> >>However, if the second action is defined as request and the first one is session, then yes the user entered data would make it to the new ActionForm and the Vector data would be gone because one would be recycled.
> >>
> >>Obviously, this is all a guess. I hope it helps somehow.
> >>
> >>Chuck
> >>--
> >>Sent via jApache.org
> >>
> >>--
> >>To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> >>For additional commands, e-mail: <ma...@jakarta.apache.org>
> >>
> >
> >
>
> --
>
> ------------------------------------------------------------------
> - Rick Holland OO/Distributed Systems Consultant
> - ObjectAge Inc.
> - rgholland1@fedex.com
> "Logic is a wreath of pretty flowers, that smell bad"
> ------------------------------------------------------------------
>
>
>
--
Cheers
Tony。
---------------------------------------------------------------------
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Are Vectors in a FormAction set to null after a user has submitted a
form?
Posted by Rick Holland <f1...@cosd.fedex.com>.
Did you know that the ControllerServlet calls reset on a form before
populating it
from the request? If your form reset method clears the instvars it may
be the problem.
Antony Stace wrote:
>Hi Chuck
>
>I just tried having the first actions scope set to scope="session" and the second actions scope set to scope="session"
>and still the Vector data is still disapearing. I actually, for a test, set another field in ActionForm in the first action to a
>test value, I didn't have this set on the form anywhere where the user could change this value, then in the
>second action I tried to access this data, but it was not there - it too was gone. Somehow a new form is being created
>and the scope="session" is not happening.
>Any ideas anyone?
>
>Cheers
>
>Tony
>
>
>On Fri, 01 Feb 2002 07:51:12 -0500
>Chuck Cavaness <st...@japache.org> wrote:
>
>>That's sort of what I was saying. In the second action, the one that is called after the user sees the form data and makes some choices, does the scope equal to request or session? If you have both of these actions defined as session scope, then I don't believe a new ActionForm would be created during the second action. If the mapping is session, then an ActionForm will be looked for in the session, which should have been put there on the previous action (along with the Vector data in it still).
>>
>>However, if the second action is defined as request and the first one is session, then yes the user entered data would make it to the new ActionForm and the Vector data would be gone because one would be recycled.
>>
>>Obviously, this is all a guess. I hope it helps somehow.
>>
>>Chuck
>>--
>>Sent via jApache.org
>>
>>--
>>To unsubscribe, e-mail: <ma...@jakarta.apache.org>
>>For additional commands, e-mail: <ma...@jakarta.apache.org>
>>
>
>
--
------------------------------------------------------------------
- Rick Holland OO/Distributed Systems Consultant
- ObjectAge Inc.
- rgholland1@fedex.com
"Logic is a wreath of pretty flowers, that smell bad"
------------------------------------------------------------------
Re: Are Vectors in a FormAction set to null after a user has submitted a form?
Posted by Antony Stace <s4...@yahoo.com>.
Hi Chuck
I just tried having the first actions scope set to scope="session" and the second actions scope set to scope="session"
and still the Vector data is still disapearing. I actually, for a test, set another field in ActionForm in the first action to a
test value, I didn't have this set on the form anywhere where the user could change this value, then in the
second action I tried to access this data, but it was not there - it too was gone. Somehow a new form is being created
and the scope="session" is not happening.
Any ideas anyone?
Cheers
Tony
On Fri, 01 Feb 2002 07:51:12 -0500
Chuck Cavaness <st...@japache.org> wrote:
> That's sort of what I was saying. In the second action, the one that is called after the user sees the form data and makes some choices, does the scope equal to request or session? If you have both of these actions defined as session scope, then I don't believe a new ActionForm would be created during the second action. If the mapping is session, then an ActionForm will be looked for in the session, which should have been put there on the previous action (along with the Vector data in it still).
>
> However, if the second action is defined as request and the first one is session, then yes the user entered data would make it to the new ActionForm and the Vector data would be gone because one would be recycled.
>
> Obviously, this is all a guess. I hope it helps somehow.
>
> Chuck
> --
> Sent via jApache.org
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
Cheers
Tony。
---------------------------------------------------------------------
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Are Vectors in a FormAction set to null after a user has submitted a form?
Posted by Chuck Cavaness <st...@japache.org>.
That's sort of what I was saying. In the second action, the one that is called after the user sees the form data and makes some choices, does the scope equal to request or session? If you have both of these actions defined as session scope, then I don't believe a new ActionForm would be created during the second action. If the mapping is session, then an ActionForm will be looked for in the session, which should have been put there on the previous action (along with the Vector data in it still).
However, if the second action is defined as request and the first one is session, then yes the user entered data would make it to the new ActionForm and the Vector data would be gone because one would be recycled.
Obviously, this is all a guess. I hope it helps somehow.
Chuck
--
Sent via jApache.org
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Are Vectors in a FormAction set to null after a user has submitted a form?
Posted by Antony Stace <s4...@yahoo.com>.
Ok...I think I know what is going on, but can someone please tell me if this is
correct or not.
Action1 sets up the ActionForm and sets a number of variables in it, including the Vectors which are
used to generate the drop down list boxes.
The form is displayed to the user with the values which were populated in the form.
The user submits the form, a new ActionForm is created and the variables in the fields the
user filled in on the form they submitted are set in the new ActionForm. The values in this new ActionForm
are then passed to the processing Action? The Vectors I populated in Action1 are not set in the new ActionForm
because since the user does not set them in the form they submit.
Does this sound correct?
Cheers
Tony
On Fri, 1 Feb 2002 16:46:14 +0900
Antony Stace <s4...@yahoo.com> wrote:
> Thanks for the reply Chuck.
>
> The action I am calling is the first action after the form has been filled in and the user submits the form. All
> the data should still be in the form. I can access all the other variables in this ActionForm which are of type String, so
> I find it strange that the Vectors have become null.
> Any ideas?
>
>
> Cheers
>
> Tony
>
> On Fri, 01 Feb 2002 02:37:38 -0500
> Chuck Cavaness <st...@japache.org> wrote:
>
> > Just guessing, but the reason the Vectors are null is probably because the action that is being called is configured as request scope and not session in the Struts configuration file. Therefore, after the HTML page is drawn (using the Vectors to populate the drop-down boxes), the ActionForm is recycled because the request is complete. If you need data like this to stick around and not have to get it again from your database or backend, then you either going to have to make the action session scope, or hide the data in the page. Take a look at the ActionMapping defined for the action being called and see if it doesn't have something like scope="request". Actually, I think the default is request, so if you don't have a line scope="request" in the mapping, it will default to request scope.
> >
> > You might try making this scope="session". Check out the JavaDoc on the ActionMapping class for more information.
> >
> > Chuck
> >
> > p.s. Is anyone really using the Vector class anymore? Why aren't you using List/ArrayList? Just curious.
> > --
> > Sent via jApache.org
> >
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Are Vectors in a FormAction set to null after a user has submitted a form?
Posted by Antony Stace <s4...@yahoo.com>.
Thanks for the reply Chuck.
The action I am calling is the first action after the form has been filled in and the user submits the form. All
the data should still be in the form. I can access all the other variables in this ActionForm which are of type String, so
I find it strange that the Vectors have become null.
Any ideas?
Cheers
Tony
On Fri, 01 Feb 2002 02:37:38 -0500
Chuck Cavaness <st...@japache.org> wrote:
> Just guessing, but the reason the Vectors are null is probably because the action that is being called is configured as request scope and not session in the Struts configuration file. Therefore, after the HTML page is drawn (using the Vectors to populate the drop-down boxes), the ActionForm is recycled because the request is complete. If you need data like this to stick around and not have to get it again from your database or backend, then you either going to have to make the action session scope, or hide the data in the page. Take a look at the ActionMapping defined for the action being called and see if it doesn't have something like scope="request". Actually, I think the default is request, so if you don't have a line scope="request" in the mapping, it will default to request scope.
>
> You might try making this scope="session". Check out the JavaDoc on the ActionMapping class for more information.
>
> Chuck
>
> p.s. Is anyone really using the Vector class anymore? Why aren't you using List/ArrayList? Just curious.
> --
> Sent via jApache.org
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Are Vectors in a FormAction set to null after a user has submitted a form?
Posted by Borislav Iordanov <bo...@kobrix.com>.
Well, for one thing, Vectors are synchronized and ArrayLists aren't. So the
latter are faster (I've heard something like 20% faster) and preferable when
you don't need synchronization. Same goes for Hashtable vs. HashMap and in
general old vs new collection classes.
Boris
On Fri, 01 Feb 2002, you wrote:
> Hi Chuck,
>
> I use Vector all the time. I'm curious why who feel that List/ArrayList is
> preferable.
>
> Dave D
>
>
> ----- Original Message -----
> From: "Chuck Cavaness" <st...@japache.org>
> To: <st...@jakarta.apache.org>
> Sent: Friday, February 01, 2002 2:37 AM
> Subject: Re: Are Vectors in a FormAction set to null after a user has
> submitted a form?
>
>
> >
> > p.s. Is anyone really using the Vector class anymore? Why aren't you using
> List/ArrayList? Just curious.
> > --
>
>
>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Are Vectors in a FormAction set to null after a user has submitted a form?
Posted by dderry <dd...@acm.org>.
Hi Chuck,
I use Vector all the time. I'm curious why who feel that List/ArrayList is
preferable.
Dave D
----- Original Message -----
From: "Chuck Cavaness" <st...@japache.org>
To: <st...@jakarta.apache.org>
Sent: Friday, February 01, 2002 2:37 AM
Subject: Re: Are Vectors in a FormAction set to null after a user has
submitted a form?
>
> p.s. Is anyone really using the Vector class anymore? Why aren't you using
List/ArrayList? Just curious.
> --
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Are Vectors in a FormAction set to null after a user has submitted a form?
Posted by Chuck Cavaness <st...@japache.org>.
Just guessing, but the reason the Vectors are null is probably because the action that is being called is configured as request scope and not session in the Struts configuration file. Therefore, after the HTML page is drawn (using the Vectors to populate the drop-down boxes), the ActionForm is recycled because the request is complete. If you need data like this to stick around and not have to get it again from your database or backend, then you either going to have to make the action session scope, or hide the data in the page. Take a look at the ActionMapping defined for the action being called and see if it doesn't have something like scope="request". Actually, I think the default is request, so if you don't have a line scope="request" in the mapping, it will default to request scope.
You might try making this scope="session". Check out the JavaDoc on the ActionMapping class for more information.
Chuck
p.s. Is anyone really using the Vector class anymore? Why aren't you using List/ArrayList? Just curious.
--
Sent via jApache.org
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>