You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Lucero, Dennis M" <de...@hp.com> on 2004/08/21 02:52:46 UTC
form problem
Does anyone know how to do this or why it does not work?
Both these methods would be called from an action class.
Function void useMyForm(ActionForm form){
SomeFormClass myForm = new SomeFormClass();
myForm.setName("Blah");
myForm.setAge("289");
etc...
form = myForm;
}
When I get to the jsp the fields are not populated with the form
variables
.
why does this not work but the following way does.
Function void fillInForm(ActionForm form){
SomeFormClass myForm = (SomeFormClass)form;
myForm.setName("Blah");
myForm.setAge("289");
etc...
}
Using this "normal" way when I get to the jsp the fields are populated
with the form variables.
How can a use something similar to the first method?
I am he, as you are he, as you are me, and we are all together.
Re: form problem
Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Struts creates and stores the ActionForm in request or session scope. If you
create a new form to replace the one automatically created by Struts, you
also need to store it under the appropriate key in either the session or
request.
Look at the the processActionForm() method in RequestProcessor - you need to
store it the same way.
http://cvs.apache.org/viewcvs.cgi/jakarta-struts/src/share/org/apache/struts/action/
Niall
----- Original Message -----
From: "Lucero, Dennis M" <de...@hp.com>
To: <st...@jakarta.apache.org>
Sent: Saturday, August 21, 2004 1:52 AM
Subject: form problem
Does anyone know how to do this or why it does not work?
Both these methods would be called from an action class.
Function void useMyForm(ActionForm form){
SomeFormClass myForm = new SomeFormClass();
myForm.setName("Blah");
myForm.setAge("289");
etc...
form = myForm;
}
When I get to the jsp the fields are not populated with the form
variables
.
why does this not work but the following way does.
Function void fillInForm(ActionForm form){
SomeFormClass myForm = (SomeFormClass)form;
myForm.setName("Blah");
myForm.setAge("289");
etc...
}
Using this "normal" way when I get to the jsp the fields are populated
with the form variables.
How can a use something similar to the first method?
I am he, as you are he, as you are me, and we are all together.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: form problem
Posted by Kishore Senji <ks...@gmail.com>.
On Fri, 20 Aug 2004 18:52:46 -0600, Lucero, Dennis M
<de...@hp.com> wrote:
> Does anyone know how to do this or why it does not work?
>
That's how java works. Java copies and passes the reference by value.
So assignments to a copy of the reference will not change the original
object.
Refer: http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html
> Both these methods would be called from an action class.
>
> Function void useMyForm(ActionForm form){
> SomeFormClass myForm = new SomeFormClass();
> myForm.setName("Blah");
> myForm.setAge("289");
> etc...
>
> form = myForm;
The above assignment doesn't modify the original form once you are out
of this method, since it is a copy of the reference.
Thanks,
Kishore Senji
>
> How can a use something similar to the first method?
>
> I am he, as you are he, as you are me, and we are all together.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org