0

I'm using Websphere Portal 8 with Primefaces 3.5. The requirement is that when the session times out, the user is redirected to a session timeout page which has a button on it that when clicked takes the user back to the login page. The login page contains a portlet as does the Session Timeout page - both are within the same portlet application. I am redirecting to the session timeout page successfully using an ImplicitLogoutFilter:

@Override
public void logout(HttpServletRequest request, HttpServletResponse response,        FilterChainContext filterContext, LogoutFilterChain chain) throws LogoutException, LoginException {
chain.logout(request, response, filterContext);
if (filterContext.getRedirectURL() != null) {
if (logger.isLoggable(Level.FINEST)) {
logger.logp(Level.FINEST, CLASS_NAME, MethodName.LOGOUT, "Redirecting to session timeout page: " + SESSION_TIMEOUT_PAGE_URL);
}
filterContext.setRedirectURL(SESSION_TIMEOUT_PAGE_URL);
}
}

The portlet on the session timeout page contains a button which calls a portlet action that redirects to the login page:

public void navigateToPortalPage(String pageUniqueName) throws RpmPortalException {
    final String methodName = "navigateToPortalPage";
    RpmPortalPage portalPage = getNavigationManager().getPortalPage(pageUniqueName, getPortletRequest(), getPortletResponse());
    try {
        FacesContext context = getFacesContext();
        if (context != null) {
            context.getExternalContext().redirect(portalPage.getUrl());
            context.responseComplete();
        }
    } catch (IOException e) {
        RpmExceptionUtils.logAndThrowException(CLASSNAME, methodName + "(" + pageUniqueName + ")", RpmErrorCode.RPM_CONFIG_00004, getLoggedinUser(), e);
    }

}

However, when the button is clicked instead of going to the login page, a ViewExpired exception is thrown instead. This exception is handled by an exception handler which handles exceptions, redirecting to an error page and displaying an error to the user.

My question is how do I avoid the ViewExpired Exception after the session has expired as I just want to be able to redirect to the login page without the ViewExpiredException occurring in this case,

Thanks in advance for your help

zargarf
  • 633
  • 6
  • 18
  • Take a look at this http://www.gregbugaj.com/?p=164 – neni Mar 14 '13 at 11:41
  • @neni: this isn't exactly what the OP asked, plus that solution breaks `@ViewScoped` beans altogether and thus requires that you're using only `@RequestScoped` beans. – BalusC Mar 14 '13 at 11:53
  • The view handler solution didn't work for us as we already tried using it – zargarf Mar 14 '13 at 14:05

1 Answers1

2

My question is how do I avoid the ViewExpired Exception after the session has expired as I just want to be able to redirect to the login page without the ViewExpiredException occurring in this case

Just specify the login page as error page of ViewExpiredException.

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/login.xhtml</location>
</error-page>

(this assumes that you've mapped faces servlet on *.xhtml, otherwise alter accordingly)

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hi....as the login portlet is on a separate portal page I modified the Exception Handler to check for a ViewExpired exception and then redirect to the login page whereby the portlet renders ok. Thanks for your help guys – zargarf Mar 14 '13 at 15:07