citress
citress

Reputation: 909

JSF2 + Spring: View scoped bean not restored on back button?

I have a page that displays folders in a directory. It works just like Windows Explorer, but my page displays the folders using a datatable. When the user drills into a folder by clicking on the folder name, I will re-display the same page but with a new instance of the backing bean with fresh data. The back bean is a View scoped bean. It is a Spring managed bean using Spring's custom View scope, not a JSF Managed Bean. When I use the browser back button to go back to this page, the browser issues a GET request to re-render the page.

The problem is that on browser back, I want the page to render data pertaining to the LAST folder I'm in, not the current folder. Currently when I hit the browser back button, a new instance of the bean is created, initializing itself with the current folder (saved in Session). I was hoping that my View scoped bean could be restored on back button submission (i.e. not a new instance creation) but I realize that might not be possible since it is a Spring managed bean. Are there any ideas as to how I can cache the bean together with the viewId on the page, or will switching to using a JSF Managed bean make a difference. I'd much prefer the former approach if possible, but am interested to hear if the latter approach would work.

Upvotes: 0

Views: 1521

Answers (1)

BalusC
BalusC

Reputation: 1108642

This is entirely working as designed.

If you want to deal with request based parameters, then you should be providing request parameters in the URL. E.g. page.xhtml?folder=foo. You can use <h:link><f:param> to create links with params and you can use <f:viewParam> to set it as bean property.

See also:

Upvotes: 1

Related Questions