0

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.

citress
  • 889
  • 3
  • 13
  • 35
  • I don't think there is something to do with Bean scope in JSF or Spring.It should work in both cases with same properties inherited when you port `@viewscoped` from JSF to Spring. – SRy Mar 13 '13 at 17:50
  • Just one moment - I almost sure you are using ViewScope like this - http://comdynamics.net/blog/109/spring3-jsf2-view-scope/ , but it will lead you to memory leaks (and absence of @PreDestroy support). Here you can get production-tested version - https://github.com/michail-nikolaev/primefaces-spring-scopes – Michail Nikolaev Mar 13 '13 at 21:30
  • @MichailNikolaev I've never heard that Spring's scope management has memory leaks. I am defining ViewScope just like the link describes. Everywhere I've looked on Stackoverflow and other reputable sites all point to that very method for defining custom ViewScope in Spring. I guess I'm a little skeptical of that claim. – citress Mar 14 '13 at 13:07
  • @citress, it is not leak in Spring, but in custom ViewScope implementation. When view go to be deleted ViewScope not removes beans from Spring context. – Michail Nikolaev Mar 14 '13 at 13:15
  • So, Spring does not know anything regarding JSF view scope. Each time you create new bean in view scope - you ask Spring to do it. So, when some view goes to be cleared - spring don't know about it and will manage beans infinitely. see your problem reported by other man - http://stackoverflow.com/questions/10888084/managed-beans-with-custom-viewscope – Michail Nikolaev Mar 14 '13 at 13:29

1 Answers1

1

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555