In our application we use jsf,we have to redirect the user to home page after their session will be expired.For that i need a path of the home page which i kept in my logout managed bean as a managed bean property.But after session expired if i try to access that it will arise null pointer exception(managed bean becomes null).Then i have decide to try alternative (i.e)create logout class manually and try to access the property, at that time the property which i wants to access is becom开发者_Go百科e null.How can i access that property? Please help me. Thanks in advance.
In addition to the previous answer:
You could use (in web.xml)
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>viewexpired.jsp</location>
</error-page>
Or Context Parameters instead of Session Attributes. See:
- http://tomcat.apache.org/tomcat-5.5-doc/config/context.html
- http://safebox.guisho.com/jsf-how-to-get-webxml-parameters
Or use (in faces-context.xml)
<managed-bean-scope>application</managed-bean-scope>
for your bean, so it will stay independent from the session.
Correct way of doing this is declaring exception handler factory in faces-config.xml, then implementing the factory by subclassing javax.faces.context.ExceptionHandlerFactory
, and then overriding handle()
method in your implementation of javax.faces.context.ExceptionHandlerWrapper
.
There you should analyze the exception for the ViewExpiredException
class and redirect to your view expired page in that case.
精彩评论