|
From: Rob B. <cro...@ya...> - 2004-09-20 20:02:10
|
Hey Brian,
I don't know about using separate bean factories for
handling session state because usually bean factories
are for creating new (prototype) objects or dishing up
singletons, not storing objects that have been
manipulated in the application. I don't think bean
factories will do what your looking to do. Although I
know where your trying going with it. ;)
If your really set on trying this approach though you
can construct a new bean factory and then store it in
session. You can set it's parent to be the
application bean factory, and set where to read it's
config file from. Infact.. I've never done it, but
since a bean factory *should be* a javabean in and of
itself, you can configure your application bean
factory to have a bean factory prototype. Then all
you would do is getBean("sessionBean"), and you would
get a fully configured "session" bean to stick in
session. By extension, you could then have a "request
session bean" configured within that. So you could
then call sessionBean.getBean("requestBean") and that
would return a fully configured request scope bean
which you could store in the request object.
Now what's really neat about this is, I have been
trying to think of a good way to implement dynamic
configuration for a web application... and this looks
like it could fit perfectly. When your user begins a
new work flow you can "load" the configuration by
requesting a new session scoped bean factory... Which
would actually load the configuration file at that
time and retain all the setings until it was
explicitly refreshed or better yet, removed from
session and a new one loaded when the next workflow
started.
Now all that is needed is to have the various spring
MVC stuff look for a session bean factory BEFORE they
look at the application bean factory. This would
allow per user configuration state to be maintained..
which is exactly what you need for a dynamically
configurable application... Because you may need to
maintain whatever the configuration was when the user
started the current workflow.. but if their session
times out, or if they finish the workflow subsequent
operations should use the new configuration with the
updates.
Any chance of this capability being built into the
framework guys?
Later
Rob
--- Brian McCallister <br...@ap...> wrote:
> I may be wrong in thinking that this doesn't exist
> in Spring, if I am,
> please tell me! I cannot find anything though.
>
> In the SpringMVC configurator I would like to have
> scope BeanFactory
> instances. One, as currently, in the application
> scope, one in the
> session, and one in the request. Each factory would
> have the higher
> scope as its parent.
>
> The primary reason for this is that I would like to
> have strongly typed
> session scoped components.
>
> public class ThrowAwayFooController
> {
> private BarComponent bar;
>
> public void setBarComponent(BarComponent bar) {
> this.bar = bar; }
>
> public void doStuff() {
> bar.setSomeSessionData("wombats!");
> }
> }
>
> would sit in the request scope factory as a
> singleton, the BarComponent
> (following)
>
> public class BarComponent
> {
> private String animalType;
>
> public void setBarComponent(BarComponent bar) {
> this.bar = bar; }
>
> public void setSomeSessionData(final String
> animalsType) {
> this.animalType = animalType;
> }
>
> public String getAnimalType() { return animalType;
> }
> }
>
> would be in the session scope factory.
>
> Later throwaway controllers could also be dependent
> on BarComponent and
> receive the same one.
>
> This provides a much cleaner way of handling session
> state than using a
> flat map, I think. It also allows you to change
> component scopes by
> simply moving them to a different factory --
> presuming the hierarchy is
> respected, nothing changes (say a stateful thing
> becomes stateless so
> can be moved to the application scope, or vice
> versa).
>
> Thoughts?
>
> -Brian
>
>
>
>
>
-------------------------------------------------------
> This SF.Net email is sponsored by: YOU BE THE JUDGE.
> Be one of 170
> Project Admins to receive an Apple iPod Mini FREE
> for your judgement on
> who ports your project to Linux PPC the best.
> Sponsored by IBM.
> Deadline: Sept. 24. Go here:
> http://sf.net/ppc_contest.php
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
>
https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com
|