This is just a repost of my question and the answers from the experts. This is
so people can scan for the correct topic.
> I have a question about the use of singleton and throwaway controllers. It
> appears to me that one use of singleton controllers would be to maintain
> stateful information across controller invocations.
>
> Would this be an approriate use of these controllers or do you recommend
using
> the standard J2EE practice of HttpSession or a SessionBean?
>
It depends on the behavior you are looking for. While a singleton controller
would maintain state across invocations, that state would not be tied to a
particular user the way session data would be.
So if you want to maintain state that is common to all users (how many times
has this controller been called, or the url of some common resource or
something) then maybe the it would be appropriate. On the other hand, if you
wanted to hold a reference to the currently logged in user, then the session
would be more appropriate.
--jim
************
Even if you are using singleton controllers (say FormBeanUser), you
still need to keep the Form object somewhere - that would be the
HttpSession attribute collection. Any data shared inside a singleton
controller will be shared among all requests from all users and would
need to be protected by synchronization.
Assuming you are trying to populate a form across several invocations
using FormBeanUser, just write makeFormBean() like this:
Get bean out of session attributes
If bean does not exist
Create bean
Save in session attributes
Jeff Schnitzer
[EMAIL PROTECTED]
------------------------------------------------------------------------------
This message may contain confidential information, and is intended only for the use of
the individual(s) to whom it is addressed.
==============================================================================
-------------------------------------------------------
This SF.net email is sponsored by: Tablet PC.
Does your code think in ink? You could win a Tablet PC.
Get a free Tablet PC hat just for playing. What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en
[INVALID FOOTER]