* @param resolver the ActionResolver to set as the current one in the user session.
*/
public static void setCurrentActionResolver( ActionResolver resolver, HttpServletRequest request,
ServletContext servletContext )
{
StorageHandler sh = Handlers.get( servletContext ).getStorageHandler();
HttpServletRequest unwrappedRequest = PageFlowUtils.unwrapMultipart( request );
RequestContext rc = new RequestContext( unwrappedRequest, null );
String currentJpfAttrName = ScopedServletUtils.getScopedSessionAttrName( CURRENT_JPF_ATTR, unwrappedRequest );
String currentLongLivedJpfAttrName =
ScopedServletUtils.getScopedSessionAttrName( CURRENT_LONGLIVED_ATTR, unwrappedRequest );
if ( resolver == null )
{
sh.removeAttribute( rc, currentJpfAttrName );
sh.removeAttribute( rc, currentLongLivedJpfAttrName );
return;
}
//
// If this is a long-lived page flow, also store the instance in an attribute that never goes away.
//
if ( resolver.isPageFlow() && isLongLived( ( ( PageFlowController ) resolver ).getModuleConfig() ) )
{
String longLivedAttrName = getLongLivedFlowAttr( resolver.getModulePath() );
longLivedAttrName = ScopedServletUtils.getScopedSessionAttrName( longLivedAttrName, unwrappedRequest );
// Only set this attribute if it's not already there. We want to avoid our onDestroy() callback that's
// invoked when the page flow's session attribute is unbound.
if ( sh.getAttribute( rc, longLivedAttrName ) != resolver )
{
sh.setAttribute( rc, longLivedAttrName, resolver );
}
sh.setAttribute( rc, currentLongLivedJpfAttrName, resolver.getModulePath() );
sh.removeAttribute( rc, currentJpfAttrName );
}
else
{
sh.setAttribute( rc, currentJpfAttrName, resolver );
sh.removeAttribute( rc, currentLongLivedJpfAttrName );
}
}