当前位置: 首页>>代码示例>>Java>>正文


Java ExternalContext.getSessionMap方法代码示例

本文整理汇总了Java中javax.faces.context.ExternalContext.getSessionMap方法的典型用法代码示例。如果您正苦于以下问题:Java ExternalContext.getSessionMap方法的具体用法?Java ExternalContext.getSessionMap怎么用?Java ExternalContext.getSessionMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.faces.context.ExternalContext的用法示例。


在下文中一共展示了ExternalContext.getSessionMap方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encodeAllAsElement

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
@Override
protected void encodeAllAsElement(
  FacesContext     context,
  RenderingContext rc,
  UIComponent      component,
  FacesBean        bean
  ) throws IOException
{
   // call super...
  super.encodeAllAsElement(context, rc, component, bean);

  // now evaluate the EL
  // We need to evaluate it here and store it on the sessionMap because
  // during UploadedFileProcessor.processFile() there is no FacesContext
  RequestContext requestContext = RequestContext.getCurrentInstance();
  Object maxMemory = requestContext.getUploadedFileMaxMemory();
  Object maxDiskSpace = requestContext.getUploadedFileMaxDiskSpace();
  Object tempDir = requestContext.getUploadedFileTempDir();
  ExternalContext external = context.getExternalContext();
  Map<String, Object> sessionMap = external.getSessionMap();
  sessionMap.put(UploadedFileProcessor.MAX_MEMORY_PARAM_NAME, maxMemory);
  sessionMap.put(UploadedFileProcessor.MAX_DISK_SPACE_PARAM_NAME, maxDiskSpace);
  sessionMap.put(UploadedFileProcessor.TEMP_DIR_PARAM_NAME, tempDir);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:25,代码来源:SimpleInputFileRenderer.java

示例2: setupRequest

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
/**
 * Sets up a request for handling by the UploadedFileProcessor.  Currently this
 * copies a number of attributes from session to the request so that the
 * UploadedFileProcessor can function accordingly.
 * 
 * @param req
 */
public static void setupRequest(ExternalContext ec)
{
  //Check for Session.  If we don't have one, there is no need to set up request
  //attributes
  if(null != ec.getSession(false))
  {
    Map<String, Object> sessionMap = ec.getSessionMap();
    Map<String, Object> requestMap = ec.getRequestMap();
    
    for(String attribute:_COPIED_ATTRIBUTES)
    {
      requestMap.put(attribute, sessionMap.get(attribute));
    }
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:23,代码来源:FileUploadUtils.java

示例3: getUser

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
public User getUser() {
	final ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
	final Map<String, Object> session = context.getSessionMap();
	final Object user = session.get(USER);

	if (user != null) {
		try {
			int userId = (int) user;
			return service.findById(userId);
		} catch (ClassCastException e) {
			LOG.error("User in session not well formatted.");
			redirectLogin(context);
		}
	}else{
		context.invalidateSession();
		redirectLogin(context);
	}
	
	return null;
}
 
开发者ID:chr-krenn,项目名称:chr-krenn-fhj-ws2017-sd17-pse,代码行数:21,代码来源:Session.java

示例4: getWindowMap

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
/**
 * Returns a Map of objects associated with the current window if any.  If there is no
 * current window, the Session Map is returned.
 * @return Map for storing objects associated with the current window.
 * @see org.apache.myfaces.trinidad.context.Window#getWindowMap
 */
public Map<String, Object> getWindowMap()
{
  WindowManager wm = getWindowManager();

  ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();

  Window window = wm.getCurrentWindow(extContext);

  if (window != null)
  {

    return window.getWindowMap();
  }
  else
  {
    return extContext.getSessionMap();
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:25,代码来源:RequestContext.java

示例5: _getRequest

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
private ServletRequest _getRequest(ExternalContext ec)
{
  String uid = ec.getRequestParameterMap().get(_LAUNCH_KEY);
  if(uid != null)
  {
    /**
     * We use pageflow scope so that if something fails on the redirect, we
     * have a chance of getting cleaned up early.  This will not always happen
     * so the object may stick around for a while.
     */
    Map<String, Object> sessionMap = ec.getSessionMap();
    
    LaunchData data = (LaunchData)sessionMap.remove(_getKey(uid));
    
    //We are returning from a dialog:
    if(data != null)
    {
      Map<String, Object> requestMap = ec.getRequestMap();

      //Setting the flag to properly support isExecutingDialogReturn.
      //This is needed for isExecutingDialogReturn.
      requestMap.put(_IS_RETURNING_KEY, Boolean.TRUE);  
      
      UIViewRoot launchView = data.getLaunchView();
      if(launchView != null)
      { 
        requestMap.put(RequestContextImpl.LAUNCH_VIEW, data.getLaunchView());
      }
      
      return new ReplaceParametersRequestWrapper(
           (HttpServletRequest) ec.getRequest(), 
           data.getLaunchParam());
    }
  }
  
  return (ServletRequest)ec.getRequest();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:38,代码来源:TrinidadFilterImpl.java

示例6: _clearViewRootCache

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
private void _clearViewRootCache(ExternalContext extContext, String newActivePageStateKey)
{
  Map<String, Object> sessionMap = extContext.getSessionMap();
  
  // clear out all of the previous PageStates' UIViewRoots and add this page
  // state as an active page state.  This is necessary to avoid UIViewRoots
  // laying around if the user navigates off of a page using a GET
  synchronized(extContext.getSession(true))
  {
    // Get the session key under which we will store the session key of the PageState object holding
    // the cached UIViewRoot.  We can either store one cached UIViewRoot per window or one
    // UIViewRoot for the entire session.
    // 
    // We only store the token rather than
    // the view state itself here in order to keep fail-over Serialization from Serializing this
    // state twice, once where it appears here and the second time in the token map itself
    // See Trinidad-1779
    String keyToActivePageStateKey = (_CACHE_VIEW_ROOT_PER_WINDOW)
                                       ? _getActivePageTokenKey(extContext, RequestContext.getCurrentInstance())
                                       : _ACTIVE_PAGE_TOKEN_SESSION_KEY;
             
    String oldActivePageStateKey = (String)sessionMap.get(keyToActivePageStateKey);

    // we only need to clear out the UIViewRoot state if we're actually changing pages and thus tokens.
    if (!newActivePageStateKey.equals(oldActivePageStateKey))
    {
      if (oldActivePageStateKey != null)
      {
        PageState activePageState = (PageState)sessionMap.get(oldActivePageStateKey);

        if (activePageState != null)
        {
          activePageState.clearViewRootState();
        }
      }

      sessionMap.put(keyToActivePageStateKey, newActivePageStateKey);
    }
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:41,代码来源:StateManagerImpl.java

示例7: removeViewStatesForWindow

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
/**
 * Removes all view states per token cache identified by a <code>windowId</code>.  When token state saving is used,
 * a token cache is created for each unique window.  The windowId is used to locate the token cache.  Each PageState 
 * is located in session scope by a composite key that contains both the window id and state token.  When a system window 
 * closed event is generated, this operation should be called to purge stale view state.
 * 
 * @param extContext faces external context
 * @param windowId window id to store the state token under
 */
public static void removeViewStatesForWindow(ExternalContext extContext, String windowId)
{
  // build a key used to locate the token cache for the target windowId
  // Can't call _getTokenCacheKey() because it doesn't
  // take a window id, so directly calling _getPerWindowCacheKey
  String cacheKey = _getPerWindowCacheKey(windowId, _VIEW_CACHE_KEY, null);
  
  // use the helper factory method to locate a token cache for the window.  the 3rd actual parameter is false
  // indicating that a new cache should not be created if it doesn't exist.
  TokenCache cache = TokenCache.getTokenCacheFromSession(extContext, cacheKey, false, -1);
  if (cache != null)
  {
    // create a sub key that is used by the SubKeyMap to locate PageState per token
    // Can't call _getViewCacheKey() because it doesn't
    // take a window id, so directly calling _getPerWindowCacheKey
    String subkey = _getPerWindowCacheKey(windowId, _VIEW_CACHE_KEY, _SUBKEY_SEPARATOR);
    Map<String, Object> sessionMap = extContext.getSessionMap();
    
    // create a map that establishes a moniker (key) between the windowId and token cache used to locate the
    // associated page state.
    Map<String, PageState> stateMap = new SubKeyMap<PageState>(sessionMap, subkey);
    
    // removes all page states known by the token cache from session
    cache.clear(stateMap);
    
    // removes the token cache
    sessionMap.remove(cacheKey);
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:39,代码来源:StateManagerImpl.java

示例8: _getPageState

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
/**
 * Returns the PageState for a state token
 * @param external
 * @param token
 * @return
 */
private static PageState _getPageState(ExternalContext external, String token)
{
  // get view cache key with "." separator suffix to separate the SubKeyMap keys
  String subkey = _getViewCacheKey(external,
                                   RequestContext.getCurrentInstance(),
                                   _SUBKEY_SEPARATOR);

  Map<String, PageState> stateMap = new SubKeyMap<PageState>(
                   external.getSessionMap(),
                   subkey);

  return stateMap.get(token);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:20,代码来源:StateManagerImpl.java

示例9: getTokenCacheFromSession

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
/**
 * Gets a TokenCache from the session, creating it if needed.
 */
@SuppressWarnings("unchecked")
static public TokenCache getTokenCacheFromSession(
  ExternalContext extContext,
  String          cacheName,
  boolean         createIfNeeded,
  int             defaultSize)
{
  Map<String, Object> sessionMap = extContext.getSessionMap();

  TokenCache cache = (TokenCache)sessionMap.get(cacheName);
  
  if (cache == null)
  {
    if (createIfNeeded)
    {
      Object session = extContext.getSession(true);

      // Synchronize on the session object to ensure that
      // we don't ever create two different caches
      synchronized (session)
      {
        cache = (TokenCache)sessionMap.get(cacheName);
        
        if (cache == null)
        {
          // create the TokenCache with the crytographically random seed
          cache = new TokenCache(defaultSize, _getSeed(), cacheName);
  
          sessionMap.put(cacheName, cache);
        }
      }
    }
  }

  return cache;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:40,代码来源:TokenCache.java

示例10: _handleDialogReturn

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
private void _handleDialogReturn(ExternalContext ec)
  throws IOException
{
  Map<String, Object> reqMap = ec.getRequestMap();
  
  if(Boolean.TRUE.equals(reqMap.get(DialogServiceImpl.DIALOG_RETURN)))
  {
    /**
     * We use pageflow scope so that if something fails on the redirect, we
     * have a chance of getting cleaned up early.  This will not always happen
     * so the object may stick around for a while.
     */
    Map<String, Object> sessionMap = ec.getSessionMap();
    String uid = UUID.randomUUID().toString();
    LaunchData data = new LaunchData((UIViewRoot)reqMap.get(RequestContextImpl.LAUNCH_VIEW), (Map<String, String[]>) reqMap.get(RequestContextImpl.LAUNCH_PARAMETERS));
    sessionMap.put(_getKey(uid), data);
    
    //Construct URL
    //TODO: sobryan I believe some of this can be added to the RequestContextUtils to allow
    //      this url to be constructed for both portlet and servlet environments.  We'll want to research.
    HttpServletRequest req = (HttpServletRequest) ec.getRequest();
    StringBuffer url = req.getRequestURL().append("?");
    String queryStr = req.getQueryString();
    if((queryStr != null) && (queryStr.trim().length() >0))
    {
      url.append(queryStr)
         .append("&");
    }
    
    url.append(_LAUNCH_KEY)
       .append("=")
       .append(uid);

    //Extensions to Trinidad may have alternatve means of handling PPR.  This
    //flag allows those extensions to for the <redirect> AJAX message to be returned.
    if (RequestContext.getCurrentInstance().isPartialRequest(_PSEUDO_FACES_CONTEXT.get()) || 
        Boolean.TRUE.equals(RequestStateMap.getInstance(ec).get(_FORCE_PPR_DIALOG_RETURN)))
    {
      //Special handling for XmlHttpRequest.  Would be cool to handle this much cleaner.
      HttpServletResponse resp = (HttpServletResponse) ec.getResponse();
      XmlHttpConfigurator.sendXmlRedirect(resp.getWriter(), url.toString());
    }
    else
    {
      ec.redirect(url.toString());
    }
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:49,代码来源:TrinidadFilterImpl.java

示例11: _saveStateToCache

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
private Object _saveStateToCache(FacesContext context, Object viewState, UIViewRoot root)
{
  ExternalContext extContext = context.getExternalContext();
  RequestContext trinContext = RequestContext.getCurrentInstance();

  TokenCache cache = _getViewCache(trinContext, extContext);
  assert(cache != null);


  // get per window view cache key with "." separator suffix to separate the SubKeyMap keys
  String subkey = _getViewCacheKey(extContext, trinContext, _SUBKEY_SEPARATOR);

  Map<String, Object>  sessionMap = extContext.getSessionMap();
  SubKeyMap<PageState> stateMap   = new SubKeyMap<PageState>(sessionMap, subkey);

  // Sadly, we can't save just a SerializedView, because we should
  // save a serialized object, and SerializedView is a *non*-static
  // inner class of StateManager
  PageState pageState = new PageState(
      context,
      _getOrCreateViewRootStateRefFactory(context, trinContext),
      viewState,
      // Save the view root into the page state as a transient
      // if this feature has not been disabled
      root);

  String requestToken = _getRequestTokenForResponse(context);
  String token;

  // If we have a cached token that we want to reuse,
  // and that token hasn't disappeared from the cache already
  // (unlikely, but not impossible), use the stateMap directly
  // without asking the cache for a new token
  if ((requestToken != null) && cache.isAvailable(requestToken))
  {
    // NOTE: under *really* high pressure, the cache might
    // have been emptied between the isAvailable() call and
    // this put().  This seems sufficiently implausible to
    // be worth punting on
    stateMap.put(requestToken, pageState);
    token = requestToken;
    // NOTE 2: we have not pinned this reused state to any old state
    // This is OK for current uses of pinning and state reuse,
    // as pinning stays constant within a window, and we're not
    // erasing pinning at all.
  }
  else
  {
    // See if we should pin this new state to any old state
    String pinnedToken = (String)extContext.getRequestMap().get(_PINNED_STATE_TOKEN_KEY);
    token = cache.addNewEntry(pageState,
                              stateMap,
                              pinnedToken);
  }


  assert(token != null);

  // And store the token for this request
  extContext.getRequestMap().put(_REQUEST_STATE_TOKEN_KEY, token);

  // clear out the view root cache, passing in the session key for the new active state
  String newActivePageStateKey = stateMap.getBaseKey(token);
  _clearViewRootCache(extContext, newActivePageStateKey);
  
  // Create a "tokenView" which abuses state to store
  // our token only
  return new Object[]{token, null};
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:70,代码来源:StateManagerImpl.java

示例12: remapViewState

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
/**
 * Give a valid state token not associated with a window, change it to be associated with
 * the specified window Id.
 * @param external The ExternalContext
 * @param windowId window id to store the state token under
 * @param token    The state token to remap from windowless to windowed
 */
public static void remapViewState(ExternalContext external, String windowId, String token)
{
  // remove the view state stored with no associated window from the session
  String oldSubkey = _getViewCacheKey(external, null, _SUBKEY_SEPARATOR);

  Map<String, Object> sessionMap = external.getSessionMap();

  Map<String, PageState> oldStateMap = new SubKeyMap<PageState>(sessionMap, oldSubkey);

  PageState viewState = oldStateMap.remove(token);

  if (viewState == null)
    throw new IllegalArgumentException();

  // store it under the windowId
  String windowSubkey = _getPerWindowCacheKey(windowId, _VIEW_CACHE_KEY, _SUBKEY_SEPARATOR);

  Map<String, PageState> newStateMap = new SubKeyMap<PageState>(sessionMap, windowSubkey);

  newStateMap.put(token, viewState);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:29,代码来源:StateManagerImpl.java

示例13: SerializationChecker

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
/**
 * Creates a SerializationChecker for this request
 * @param extContext               ExternalContext to use to initialize the SerializationChecker
 * @param checkSession If true check serializability of session attributes 
 * @param checkApplication if true, check serializability of application attributes
 * @param checkManagedBeanMutation if true, check for mutations to attributes in the session
 *                                 if checkSession is true and the application if
 *                                 checkApplication is true.
 */
private SerializationChecker(
  ExternalContext extContext,
  boolean checkSession,
  boolean checkApplication,
  boolean checkManagedBeanMutation,
  boolean checkSessionAtEnd)
{
  Map<String, Object> sessionMap = extContext.getSessionMap();
  Map<String, Object> applicationMap = extContext.getApplicationMap();
  
  if (checkManagedBeanMutation)
  {
    // note that the mutated bean checekd implicitly checks for attribute serialization as well.
    _sessionBeanChecker = new MutatedBeanChecker(sessionMap,
                                                 "Session",
                                                 extContext.getSession(true),
                                                 true);
    sessionMap = CollectionUtils.newMutationHookedMap(sessionMap, _sessionBeanChecker);
    
    // only check the application for mutations if the application checking is enabled
    if (checkApplication)
    {
      _applicationBeanChecker = new MutatedBeanChecker(applicationMap,
                                                       "Application",
                                                       extContext.getContext(),
                                                       false);
      applicationMap = CollectionUtils.newMutationHookedMap(applicationMap,
                                                            _applicationBeanChecker);
    }
    else
    {
      _applicationBeanChecker = null;
    }
  }
  else
  {
    _sessionBeanChecker     = null;
    _applicationBeanChecker = null;
    
    if (checkSession)
    {
      sessionMap = CollectionUtils.getCheckedSerializationMap(sessionMap, true);
    }

    if (checkApplication)
    {
      applicationMap =  CollectionUtils.getCheckedSerializationMap(applicationMap, false);
    }        
  }
        
  _sessionMap     = sessionMap;
  _applicationMap = applicationMap;
  _checkSessionAttrs = checkSessionAtEnd;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:64,代码来源:CheckSerializationConfigurator.java

示例14: _getChangesForView

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
/**
 * Gets the in-order list of component changes for the given view.
 * @param context The FacesContext instance for this request.
 * @param sessionKey The composite session key based on the viewId 
 * @param createIfNecessary Indicates whether the underlying datastructures
 * that store the component changes needs to be created if absent.
 * @return The ChangesForView object containing information about the changes for the specified
 * viewId, including in-order list of component changes for the supplied view. This
 * will be in the same order in which the component changes were added through
 * calls to <code>addComponentChange()</code>.
 */
private ChangesForView _getChangesForView(
  FacesContext context,
  String       sessionKey,
  boolean      createIfNecessary)
{
  ExternalContext extContext = context.getExternalContext();
  Map<String, Object> sessionMap = extContext.getSessionMap();

  Object changes = sessionMap.get(sessionKey);
  
  if (changes == null)
  {
    if (createIfNecessary)
    {
      // make sure we only create this viewId's changes entry once
      Object session = extContext.getSession(true);
      
      synchronized (session)
      {
        changes = sessionMap.get(sessionKey);
        
        if (changes == null)
        {
          ChangesForView changesForView = new ChangesForView(true);
          
          sessionMap.put(sessionKey, changesForView);
          
          return changesForView;  // return the newly created changes
        }
        else
        {
          return (ChangesForView)changes;  // another thread created the changes for us          
        }
      }
    }
    else
    {
      return _EMPTY_CHANGES;  // no changes and we aren't allowed to create them
    }
  }
  else
  {
    return (ChangesForView)changes;  // we have the changes
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:57,代码来源:SessionChangeManager.java


注:本文中的javax.faces.context.ExternalContext.getSessionMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。