Struts: difference between ....??

V

Vijay

hi all,

What is the difference between using a form bean with session scope and
storing the data in session? If there's some difference, then how
should it be decided to use between the two options above.

Thanks,
 
R

Ryan Stewart

Vijay said:
hi all,

What is the difference between using a form bean with session scope and
storing the data in session? If there's some difference, then how
should it be decided to use between the two options above.
Form beans are for passing around HTML form data. Typically you would put use a
session form bean to handle a multi-page form. I can't think of any other reason
off-hand, unless for some reason you want some form to always have the same data
a user last entered in it. I'm not sure what you mean by "storing the data in
the session". You put things in the session that you may need to use over
multiple requests. An example would be a paged list. If you have 200 items but
only want to see 20 at a time, the 200 might be stored in the session so that
going forward and back can simply pull the data out of the sessino and save
extra trips to a data store.
 
M

Malte

Ryan said:
Form beans are for passing around HTML form data. Typically you would put use a
session form bean to handle a multi-page form. I can't think of any other reason
off-hand, unless for some reason you want some form to always have the same data
a user last entered in it. I'm not sure what you mean by "storing the data in
the session". You put things in the session that you may need to use over
multiple requests. An example would be a paged list. If you have 200 items but
only want to see 20 at a time, the 200 might be stored in the session so that
going forward and back can simply pull the data out of the sessino and save
extra trips to a data store.
How would you handle an application consisting of a series of forms,
each on a different page. The user must be able to go back and forth
between the pages and find the data, he or she entered, just as it was.
Potentially, this could be a lot of data.
 
S

Steve Sobol

Malte said:
How would you handle an application consisting of a series of forms,
each on a different page. The user must be able to go back and forth
between the pages and find the data, he or she entered, just as it was.
Potentially, this could be a lot of data.

This is exactly how I handled such a situation very recently:

I created a bean derived from ActionForm (actually, I believe it was
ValidatorActionForm because I wanted validation). It contained properties
corresponding to all of the form fields. In other words, I had six or seven
different forms on different JSPs and all of them were hooked into the bean.

The bean has session scope.

--
JustThe.net - Apple Valley, CA - http://JustThe.net/ - 888.480.4NET (4638)
Steven J. Sobol, Geek In Charge / (e-mail address removed) / PGP: 0xE3AE35ED

"In case anyone was wondering, that big glowing globe above the Victor
Valley is the sun." -Victorville _Daily Press_ on the unusually large
amount of rain the Southland has gotten this winter (January 12th, 2005)
 
R

Ryan Stewart

Steve Sobol said:
This is exactly how I handled such a situation very recently:

I created a bean derived from ActionForm (actually, I believe it was
ValidatorActionForm because I wanted validation). It contained properties
corresponding to all of the form fields. In other words, I had six or seven
different forms on different JSPs and all of them were hooked into the bean.

The bean has session scope.
That's a multi-page form. However if the HTML forms are not related, you should
use separate ActionForms for each.
 
R

Ryan Stewart

Malte said:
How would you handle an application consisting of a series of forms, each on a
different page. The user must be able to go back and forth between the pages
and find the data, he or she entered, just as it was. Potentially, this could
be a lot of data.

Steve described it fairly well. I'll just add that first, you need to realize
that Struts handles populating the HTML forms from the ActionForm for you. You
don't have to worry about that. Also, you have to consider what "a lot of data"
is. If you're worried about some kind of server performance issues, you'd have
to have some really huge forms: the kind a user would never have or take the
time to fill out completely.
 
S

Steve Sobol

Ryan said:
That's a multi-page form. However if the HTML forms are not related, you should
use separate ActionForms for each.

Yes. I used a multi-page form to create a "wizard". In the situation you
describe, perhaps separate ActionForms would be best if they all were in the
session scope.


--
JustThe.net - Apple Valley, CA - http://JustThe.net/ - 888.480.4NET (4638)
Steven J. Sobol, Geek In Charge / (e-mail address removed) / PGP: 0xE3AE35ED

"In case anyone was wondering, that big glowing globe above the Victor
Valley is the sun." -Victorville _Daily Press_ on the unusually large
amount of rain the Southland has gotten this winter (January 12th, 2005)
 
R

Ryan Stewart

Steve Sobol said:
Yes. I used a multi-page form to create a "wizard". In the situation you
describe, perhaps separate ActionForms would be best if they all were in the
session scope.
No, I meant totally unrelated forms, each contained in a single page. The best
approach for that would be individual ActionForms for each HTML form placed in
the request scope.
 
V

Vijay

Thankyou all for the help. I am still somewhat confused.
Let me be more clear here. I want to find out diffs between these two
things
1. I get all the data from the multiple ActionForms (scope="request")
and store them in the session using session.setAttribute(...,...)
2. I just use the single big ActionForm with scope="session"

Which one is advisable and under which conditions?

Thanks again,
 
R

Ryan Stewart

Vijay said:
Thankyou all for the help. I am still somewhat confused.
Let me be more clear here. I want to find out diffs between these two
things
1. I get all the data from the multiple ActionForms (scope="request")
and store them in the session using session.setAttribute(...,...)
2. I just use the single big ActionForm with scope="session"

Which one is advisable and under which conditions?
The question is one of semantics really. It sounds like you have one big form
spread across several pages. Technically, they are different HTML forms, but
they are all gathering information for the same purpose. Is this right? If so,
using one ActionForm with session scope would be the appropriate way to do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top