0

The application default session time out is set as 30 min, i need to keep some bean data more than 2 hours, is there any way in JSF to implement this scenario?(like defining custom scope bean and setting that been life time up-to 2 hours).

Thanks in advance.

Arulraj
  • 1
  • 2
  • 3
    You can achieve that in some way, but what you want to do seems like a design lack. What do you wan to do with that info if session is already finished? Did you think about an application scoped bean? – Aritz Oct 09 '13 at 06:20
  • try to increase your session time-out in jsf Application to 2 hours by setting it in web.xml file – hanan Ahmed Oct 09 '13 at 16:57
  • Assuming as if you really want to store some data or an array of properties, why don't you use cookies and set their max ages to 2 hours? You seem to want two conflicting changes at a time. – Narayana Nagireddi Oct 10 '13 at 04:57

2 Answers2

1

No, in general it's not possible to prevent the container from destroying a JSF bean when it's not needed anymore.

So, you can either use an ApplicationScoped bean, or a Singleton EJB.

Another solution is to use a SessionScoped bean and set a different session timeout, but you will lose the data after the user invalidates the session, either by logging out or closing the browser.

Yet another solution is to persist the data to a db, but I assume you have already considered it.

Links:

Community
  • 1
  • 1
perissf
  • 15,979
  • 14
  • 80
  • 117
0

Aside from application scoped beans every scope above @RequestScoped will have to be stored in the Session, because there is no other place to store data for JSF. A custom scope cannot change that.

So when your Session is destroyed after 30 minutes, everything is lost. The best solution is to set your Session timeout to a higher value by setting it in the web.xml (in minutes):

<web-app ...>
<session-config>
    <session-timeout>120</session-timeout>
</session-config>
</web-app>

Or programmatically (in seconds):

HttpSession session = request.getSession();
session.setMaxInactiveInterval(120*60);

If you setup @SessionScoped only for those beans which need to be available for 2 hours, and use @RequestScoped or @ViewScoped for everything else, then your Session will keep only the data which you want to keep for 2 hours and everything else will be deleted much earlier.

noone
  • 19,520
  • 5
  • 61
  • 76