You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2007/03/01 16:31:12 UTC
Re: Struts session scoped forms
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Michael and Chaudhary,
Michael Jouravlev wrote:
> On 2/28/07, Chaudhary, Harsh <HC...@amfam.com> wrote:
>> I have page1.jsp which has a form which calls Page1Action which forwards
>> to page2.jsp. Also, session scoped Page1Form and Page2Form.
>>
>> In Page1Action, I do:
>>
>> Page2Form frm = new Page2Form();
>> frm.setSomeVariable("Some Value");
>>
>> Then read this value in page2.jsp to display.
Why not add another <action> mapping in between Page1Action and page2?
Something like this:
page1.jsp -- submit --> Page1Action -- fwd --> PrepPage2 --> page2.jsp
Then, set the "name" for Page1Action to "Page1Form" and the "name" for
PrepPage2 to "Page2Form". Then, you can use the form that gets provided
by Struts directly in your execute method.
>> I feel the bad part is initializing the Page2Form myself. This works
>> correctly because I think Struts checks for the form being available in
>> all scopes, finds it in session, and just uses that instead of creating
>> a new one in the Page2Form constructor.
If you call the constructor for Page2Form, you /will/ get a new object.
Struts has nothing to do with this. You must be doing something else in
your action to put this object into session or request scope.
> Why would you create an ActionForm for pure output purposes? You can
> create a POJO or even access properties of your business object.
If page2.jsp contains a form, then it is perfectly natural to use an
ActionForm to shuttle data from the action to the page.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFF5vHA9CaO5/Lv0PARAk0GAKCoH/CG22PzE7M60O0IDm26PUd1qACgtKYn
FhkoBJ8OQ2oUIwvoikdlciM=
=JWjA
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Struts session scoped forms
Posted by "Chaudhary, Harsh" <HC...@amfam.com>.
I am setting the struts form I created into session.
I agree that this is all working fine without any problems. But there is
something "icky" about it but I can't put my finger on it.
One reason could be that this is generating a coupling of the struts
form to the java code, something which the struts-config file was meant
to do, I don't know.
Harsh.
-----Original Message-----
From: Christopher Schultz [mailto:chris@christopherschultz.net]
Sent: Thursday, March 01, 2007 9:31 AM
To: Struts Users Mailing List
Subject: Re: Struts session scoped forms
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Michael and Chaudhary,
Michael Jouravlev wrote:
> On 2/28/07, Chaudhary, Harsh <HC...@amfam.com> wrote:
>> I have page1.jsp which has a form which calls Page1Action which
forwards
>> to page2.jsp. Also, session scoped Page1Form and Page2Form.
>>
>> In Page1Action, I do:
>>
>> Page2Form frm = new Page2Form();
>> frm.setSomeVariable("Some Value");
>>
>> Then read this value in page2.jsp to display.
Why not add another <action> mapping in between Page1Action and page2?
Something like this:
page1.jsp -- submit --> Page1Action -- fwd --> PrepPage2 --> page2.jsp
Then, set the "name" for Page1Action to "Page1Form" and the "name" for
PrepPage2 to "Page2Form". Then, you can use the form that gets provided
by Struts directly in your execute method.
>> I feel the bad part is initializing the Page2Form myself. This works
>> correctly because I think Struts checks for the form being available
in
>> all scopes, finds it in session, and just uses that instead of
creating
>> a new one in the Page2Form constructor.
If you call the constructor for Page2Form, you /will/ get a new object.
Struts has nothing to do with this. You must be doing something else in
your action to put this object into session or request scope.
> Why would you create an ActionForm for pure output purposes? You can
> create a POJO or even access properties of your business object.
If page2.jsp contains a form, then it is perfectly natural to use an
ActionForm to shuttle data from the action to the page.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFF5vHA9CaO5/Lv0PARAk0GAKCoH/CG22PzE7M60O0IDm26PUd1qACgtKYn
FhkoBJ8OQ2oUIwvoikdlciM=
=JWjA
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] Re: Struts session scoped forms
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
I think there's something to be said though for maintainability when
there's only a single well-known object a developer has to go to to
populate the screen, form data or not. I personally prefer the ActionForm
be viewed as a VO between the view and control, and I don't figure the
values it passes only has to be user entry.
It's a fair point about more working populating the form from VOs...
either way, not something I'm religious about or anything, just another
perspective.
Frank
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
(2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
Supplying the wheel, so you don't have to reinvent it!
On Thu, March 1, 2007 11:40 am, Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Dave,
>
> Dave Newton wrote:
>> --- Christopher Schultz wrote:
>>> If you have a form that needs to be populated,
>>> submitted, validated and possibly re-displayed, why
>>> not use an ActionForm to populate the form in
>>> the first place?
>>
>> If you're talking about only form data, sure. That's
>> why I explicitly stated I was referring to plain old
>> presentation data.
>
> Oh, okay. Yeah, I never use ActionForms merely for display. Mostly
> because it's not terribly convenient to copy data from a value object
> into an ActionForm just for display.
>
> Thanks for the clarification.
>
> - -chris
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFF5wII9CaO5/Lv0PARAncFAJ9/3V8DSpTVnWozxkgSYFbBYZ5wzACfZ1t6
> QTQl3awL3aBcg8n7N8iG1Y4=
> =3/Fh
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] Re: Struts session scoped forms
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dave,
Dave Newton wrote:
> --- Christopher Schultz wrote:
>> If you have a form that needs to be populated,
>> submitted, validated and possibly re-displayed, why
>> not use an ActionForm to populate the form in
>> the first place?
>
> If you're talking about only form data, sure. That's
> why I explicitly stated I was referring to plain old
> presentation data.
Oh, okay. Yeah, I never use ActionForms merely for display. Mostly
because it's not terribly convenient to copy data from a value object
into an ActionForm just for display.
Thanks for the clarification.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFF5wII9CaO5/Lv0PARAncFAJ9/3V8DSpTVnWozxkgSYFbBYZ5wzACfZ1t6
QTQl3awL3aBcg8n7N8iG1Y4=
=3/Fh
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
[OT] Re: Struts session scoped forms
Posted by Dave Newton <ne...@yahoo.com>.
--- Christopher Schultz wrote:
> If you have a form that needs to be populated,
> submitted, validated and possibly re-displayed, why
> not use an ActionForm to populate the form in
> the first place?
If you're talking about only form data, sure. That's
why I explicitly stated I was referring to plain old
presentation data.
d.
____________________________________________________________________________________
Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.
http://answers.yahoo.com/dir/?link=list&sid=396545367
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts session scoped forms
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dave,
Dave Newton wrote:
> --- Christopher Schultz wrote:
>> If page2.jsp contains a form, then it is perfectly
>> natural to use an ActionForm to shuttle data from
> the
>> action to the page.
>
> That's actually debatable, and has been in the past.
>
> Some people prefer to use ActionForms exclusively for
> form data and not Plain Old Presentation Data. I am of
> this camp.
If you have a form that needs to be populated, submitted, validated and
possibly re-displayed, why not use an ActionForm to populate the form in
the first place?
Otherwise, you have crazy code in the form just to pre-populate form
values -- checking both the POJO (or whatever) and the ActionForm.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFF5vca9CaO5/Lv0PARAqMMAJsETWtv28HaY1ivgKYKGrcgo+zv3gCfS424
nU2G8pwJP+kw3/1jLMaXh1k=
=8LTF
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts session scoped forms
Posted by Dave Newton <ne...@yahoo.com>.
--- Christopher Schultz wrote:
> If page2.jsp contains a form, then it is perfectly
> natural to use an ActionForm to shuttle data from
the
> action to the page.
That's actually debatable, and has been in the past.
Some people prefer to use ActionForms exclusively for
form data and not Plain Old Presentation Data. I am of
this camp.
d.
____________________________________________________________________________________
Want to start your own business?
Learn how on Yahoo! Small Business.
http://smallbusiness.yahoo.com/r-index
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org