You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bhaskar Gopalan <bg...@adaptintel.com> on 2002/04/15 20:36:45 UTC

Managing bean

Hi,
I'm new to struts and have this question:

I have a jsp that talks to a form bean. After successful validation, this
formbean is
passed to action.perform(). Now I am creating a bean (corresponding to a db
row) in 
the action class using the data from the formbean. Now, where do I store
this bean
and how do I access it from the action class later? I guess only one
instance of
the action is created for all the sessions. So, I cannot store the bean as
an
instance variable of the action class.

Thnx,
GB

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Managing bean

Posted by Joseph Barefoot <jo...@hereuare.com>.
Do you need to store more than one instance of your "db-row" bean per
session?  If not, then I would just store the bean in the session like so:

request.getSession().setAttribute("MyActionClass.dbRowBeanClassName",
dbRowBeanInstance)

Of course, you're free to use whatever identifier you like, but I use the
Action Class name followed by a '.' and then the class name of the bean I'm
storing.  The other option, if the form bean has session scope, is to create
a field in your form bean for the dbRowBean and store it there instead.

If you need to store more than one dbRowBean object per session, you'll have
to come up with a naming scheme of some sort. :)

cheers,
Joe

-----Original Message-----
From: Bhaskar Gopalan [mailto:bgopalan@adaptintel.com]
Sent: Monday, April 15, 2002 11:37 AM
To: Struts Group (E-mail)
Subject: Managing bean


Hi,
I'm new to struts and have this question:

I have a jsp that talks to a form bean. After successful validation, this
formbean is
passed to action.perform(). Now I am creating a bean (corresponding to a db
row) in
the action class using the data from the formbean. Now, where do I store
this bean
and how do I access it from the action class later? I guess only one
instance of
the action is created for all the sessions. So, I cannot store the bean as
an
instance variable of the action class.

Thnx,
GB

--
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: Managing bean

Posted by Alex Paransky <ap...@standardset.com>.
You have a number of options:

1. If you want to store the data for a while, then put it in to a session.
While you should not probably put the entire ResultSet into the session, you
might read a single row in a java bean, and store the bean in the session.

2. If it's a single row that you have read, and you just want to display it
on the next page, put your bean (the one which represents the row) into the
request (setAttribute), and forward to the page that will render (display)
the data from the row.  After the process completes, the data is lost.  On
the next request, you might have to re-find your row again. Your page, might
want to layout the <hidden> field with the ID of the row you have read, so
that you can continue your processing when the user does something next.

-AP_
http://www.alexparansky.com
Java/J2EE Architect/Consultant
http://www.myprofiles.com/member/view.do?profileId=127

-----Original Message-----
From: Bhaskar Gopalan [mailto:bgopalan@adaptintel.com]
Sent: Monday, April 15, 2002 11:37 AM
To: Struts Group (E-mail)
Subject: Managing bean


Hi,
I'm new to struts and have this question:

I have a jsp that talks to a form bean. After successful validation, this
formbean is
passed to action.perform(). Now I am creating a bean (corresponding to a db
row) in
the action class using the data from the formbean. Now, where do I store
this bean
and how do I access it from the action class later? I guess only one
instance of
the action is created for all the sessions. So, I cannot store the bean as
an
instance variable of the action class.

Thnx,
GB

--
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>