views:

426

answers:

2

This is a question that has been bothering me for sometime. My application uses ICEFaces for our UI framework and Spring 2.5 for Dependency Injection. In addition, Spring actually maintains all of our backing beans, not the ICEFaces framework, so our faces-config is basically empty.

Navigation is not even really handled through navigation-rules. We perform manual redirects to new windows using window.open.

All of our beans are defined in our appContext file as being request-scoped. I have Page ABC which is backed by BackingBeanABC. Inside that backing bean, I have a parameter say:

private Order order;

I then have Page XYZ backed by BackingBeanXYZ. When I redirect from page ABC to page XYZ, I want to transfer the 'order' property from ABC to XYZ. The problem is since everything is request-scoped and I'm performing a redirect, I am losing the value of 'description'.

There has got to be an easier way to pass objects between beans in request scope during a redirect. Can anyone assist with this issue?

+1  A: 

Session scope solves your issue.

You can read more about it in Spring's reference documentation.

Another alternative is to set the order object directly on the HttpSession object. I would have prefered that and only have your services, controllers and repositories managed by Spring.

Espen
It does yes, but I don't want to use that as an option. All managedbeans in our app are request-scope.
Why? Are you trying to let a request-scoped bean behave like a sessions scoped bean?
Espen
I know that Session works here, but this is not a crazy scenario that I have here. What I need is a scope that is longer than request, but less than session. Its what Spring Webflow is built on and Seam's Conversation scope is built on (neither of which I'm allowed to us -- don't ask).
The Servlet API only gives you the opportunity to store data in a session or in a cookie. If you're not allowed to use a framework that gives you this functionality, you have to write it yourself with the support of the Servlet API.
Espen
@smayers: put in session and *remove* it from session on 1st next access. All conversation-scoped like techniques also does that "under the hoods". If necessary you can pass some unique ID along it so that it doesn't interfere with other requests. You only have to append that as parameter in redirect URL.
BalusC
The problem with removing it when accessed though is that the if the user refreshes the page, an error is thrown because the unique ID they used to access the data from session no longer points to anything meaningful.
@smayers81: Then you have to implement support for this as well. Maybe store it as something else related to the page name in the session object. It's solvable! If you're totally stuck, then try to study how Spring MVC does it. But I can guarantee you that they're using the session object to store objects in conversation scope.
Espen
I agree, Espen. I am planning on reviewing how this is handled by both Spring MVC and Seam's conversation scope. Thanks for the help everyone. I will comment with my findings (if anyone cares).
A short summary would have been interesting!
Espen
+1  A: 

Create a single session scoped bean that the request scoped beans can reference via the FacesContext.

Naganalf
I actually did that a while ago and was vilified for it. I might go back to it. It seemed to work fine.
Vilified for putting session data into a session context? Good times!
Naganalf