>In an earlier post, Craig responded to a question by saying "Personally,
>I consider putting view controllers in session scope to be a pretty bad
>idea, and would
>lean towards making this a restriction.   (Putting non-view-controller
>backing beans in session scope to save state across sessions is fine.)"
>
>(The whole post is included below if you're interested) 
>
>This makes sense if a ViewController is our in-memory object
>representation of a page, since a page only lasts for one request.
>
>Well, I was looking at the Shale samples and in the rolodex example, the
>ViewController (backing bean) for the rolodex is stored in session
>scope.
>
>  <managed-bean>
>    <description>
>       View controller for the JSP view rolodex usecase
>    </description>
>    <managed-bean-name>rolodex</managed-bean-name>
>    <managed-bean-class>
>      org.apache.shale.usecases.rolodex.Rolodex
>    </managed-bean-class>
>    <managed-bean-scope>session</managed-bean-scope>
>  </managed-bean>
>
>I understand that samples don't have to reflect best-practices, but I'm
>curious as to what the best-practice would be.
>

The rolodex example doesn't use any of the view controller callback methods but 
the full html and xml template views assume the default "managed-bean-name" 
symbol 
is the name of the view controller.  In these usecase apps we tried to isolate 
the features demonstrated.


But, you are right, this is not the best practice use.

>Should your ViewController object be in request scope, and get injected
>with a non-view-Controller that could live in any scope.  The
>non-view-Controller can have model objects injected into it.  This way
>the ViewController can handle all view related methods, and pass through
>to the non-view-Controller for business methods which then get passed on
>to the model objects.
>
>Should your ViewController object live in request scope, and just get
>variously scoped model objects injected, and after that just work as
>both a View and non-view Controller.
>

The problem you run into with the view controller in session scope is when you 
have a post back and then navigation to the same page.  In this scenario, the 
callback methods are invoked twice on the same instance since it's session 
scoped.
The symbols example would be a better example 
(http://svn.apache.org/viewvc/struts/shale/trunk/shale-apps/shale-clay-usecases/src/main/java/org/apache/shale/usecases/symbols/RegistrationForm.java?view=markup)

>Shoud you do something else completely different from either of those
>two scenarios?
>
>
>JB

Gary

Reply via email to