Re: how to avoid creating new Action class instance for every request in STRUTS2

2007-09-29 Thread Zarar Siddiqi
If you're using Spring you could define your action bean as a
singleton and that would do the trick since the same instance would
always be reused.  Note that this is pretty crazy in most cases,
you're probably better off storing our objects in session scope like
Chris suggested.

Zarar

On 9/29/07, Jose4u [EMAIL PROTECTED] wrote:

 implementation: I have .jsp in which i have two text box and a Add button.
 whenever i enter something in the two text box and click on Add button the
 values  needs to be added to the html table which is right down the entry
 area with two text boxes. Whenver i Click on add i am calling a Action class
 where i have a colection object in which i add the two text box values to
 the collection object and on SUCCESS comming to .jsp i iterate the
 collection object and display it in the .jsp.
 Problem facing:  Whenever i call the action class and i am adding, its
 adding and displaying in the html table but the next time i add the previous
 values in the collection gets removed At a time only one object is there in
 the collection. The same implementation i did it in Struts 1 it was working
 fine, but in struts 2 its not retaining the values in the collection.Is it
 because for every call a new Action instance is created in Struts2? Is there
 any intercepto i need to use? Please provide me a solution to implement this
 functionality in struts 2

 Thanks in advance
 Jose


 --
 View this message in context: 
 http://www.nabble.com/how-to-avoid-creating-new-Action-class-instance-for-every-request-in-STRUTS2-tf4538022.html#a12952131
 Sent from the Struts - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



how to avoid creating new Action class instance for every request in STRUTS2

2007-09-28 Thread Jose4u

implementation: I have .jsp in which i have two text box and a Add button.
whenever i enter something in the two text box and click on Add button the
values  needs to be added to the html table which is right down the entry
area with two text boxes. Whenver i Click on add i am calling a Action class
where i have a colection object in which i add the two text box values to
the collection object and on SUCCESS comming to .jsp i iterate the
collection object and display it in the .jsp.
Problem facing:  Whenever i call the action class and i am adding, its
adding and displaying in the html table but the next time i add the previous
values in the collection gets removed At a time only one object is there in
the collection. The same implementation i did it in Struts 1 it was working
fine, but in struts 2 its not retaining the values in the collection.Is it
because for every call a new Action instance is created in Struts2? Is there
any intercepto i need to use? Please provide me a solution to implement this
functionality in struts 2

Thanks in advance 
Jose


-- 
View this message in context: 
http://www.nabble.com/how-to-avoid-creating-new-Action-class-instance-for-every-request-in-STRUTS2-tf4538022.html#a12952131
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: how to avoid creating new Action class instance for every request in STRUTS2

2007-09-28 Thread Chris Pratt
You're probably right, whenever the Action is created, it's
initialized.  In struts 1, since the Actions didn't go away, any data
was retained.  This was usually the source of many, many bugs.  It's a
very rare condition when you want the data from one invocation of the
Action to carry forward to the next, especially since in a multiuser
system, it may not be the same user that hits the action twice in a
row.  So the second user would get the first users data.  In order to
help prevent these errors, the designers of Struts 2 made a conscious
decision to create the Action instances as needed.

So to emulate what you had in Struts 1, where everyone shares one pool
of data from the action, just put your list in the Application scope
(ServletContext) and retrieve it when you initialize your Action.

If you really only want this to allow each user to maintain their own
list (not like the Struts 1 implementation), you could put it in
Session scope instead.

  (*Chris*)

On 9/28/07, Jose4u [EMAIL PROTECTED] wrote:

 implementation: I have .jsp in which i have two text box and a Add button.
 whenever i enter something in the two text box and click on Add button the
 values  needs to be added to the html table which is right down the entry
 area with two text boxes. Whenver i Click on add i am calling a Action class
 where i have a colection object in which i add the two text box values to
 the collection object and on SUCCESS comming to .jsp i iterate the
 collection object and display it in the .jsp.
 Problem facing:  Whenever i call the action class and i am adding, its
 adding and displaying in the html table but the next time i add the previous
 values in the collection gets removed At a time only one object is there in
 the collection. The same implementation i did it in Struts 1 it was working
 fine, but in struts 2 its not retaining the values in the collection.Is it
 because for every call a new Action instance is created in Struts2? Is there
 any intercepto i need to use? Please provide me a solution to implement this
 functionality in struts 2

 Thanks in advance
 Jose


 --
 View this message in context: 
 http://www.nabble.com/how-to-avoid-creating-new-Action-class-instance-for-every-request-in-STRUTS2-tf4538022.html#a12952131
 Sent from the Struts - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]