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


Java ExternalContext.getSession方法代码示例

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


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

示例1: 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

示例2: getDescription

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
@Override
public String getDescription(boolean includeClientInfo) {
	ExternalContext externalContext = getExternalContext();
	StringBuilder sb = new StringBuilder();
	sb.append("context=").append(externalContext.getRequestContextPath());
	if (includeClientInfo) {
		Object session = externalContext.getSession(false);
		if (session != null) {
			sb.append(";session=").append(getSessionId());
		}
		String user = externalContext.getRemoteUser();
		if (StringUtils.hasLength(user)) {
			sb.append(";user=").append(user);
		}
	}
	return sb.toString();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:FacesWebRequest.java

示例3: _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

示例4: 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

示例5: _logIdString

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
private static void _logIdString(FacesContext context)
{   
  ExternalContext externalContext = context.getExternalContext();    
  String sessionId = "";
  Object session = externalContext.getSession(false);
  
  if (session instanceof HttpSession)
  {
    sessionId = ((HttpSession)session).getId();
  }      

  StringBuffer buff = _getLogBuffer(context);
  buff.append("Session Id = ").append(sessionId);
  
  WindowManager wm = RequestContext.getCurrentInstance().getWindowManager();
  if (wm != null)
  {
    Window window = wm.getCurrentWindow(externalContext);
    
    if (window != null)
    {
      buff.append("\nWindow Id = ").append(window.getId());   
    }
    else
    {
      buff.append("\nWindow Id could not be determined, window is null" ); 
    }
      
  }
  else
  {
    buff.append("\nWindow Id could not be determined, window manager null" ); 
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:35,代码来源:TokenCacheDebugUtils.java

示例6: getAttribute

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
public static Object getAttribute(String name, ExternalContext externalContext) {
	Object session = externalContext.getSession(false);
	if (session instanceof PortletSession) {
		return ((PortletSession) session).getAttribute(name, PortletSession.APPLICATION_SCOPE);
	}
	else if (session != null) {
		return externalContext.getSessionMap().get(name);
	}
	else {
		return null;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:FacesRequestAttributes.java

示例7: setAttribute

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
public static void setAttribute(String name, Object value, ExternalContext externalContext) {
	Object session = externalContext.getSession(true);
	if (session instanceof PortletSession) {
		((PortletSession) session).setAttribute(name, value, PortletSession.APPLICATION_SCOPE);
	}
	else {
		externalContext.getSessionMap().put(name, value);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:FacesRequestAttributes.java

示例8: removeAttribute

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
public static void removeAttribute(String name, ExternalContext externalContext) {
	Object session = externalContext.getSession(false);
	if (session instanceof PortletSession) {
		((PortletSession) session).removeAttribute(name, PortletSession.APPLICATION_SCOPE);
	}
	else if (session != null) {
		externalContext.getSessionMap().remove(name);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:FacesRequestAttributes.java

示例9: getAttributeNames

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
public static String[] getAttributeNames(ExternalContext externalContext) {
	Object session = externalContext.getSession(false);
	if (session instanceof PortletSession) {
		return StringUtils.toStringArray(
				((PortletSession) session).getAttributeNames(PortletSession.APPLICATION_SCOPE));
	}
	else if (session != null) {
		return StringUtils.toStringArray(externalContext.getSessionMap().keySet());
	}
	else {
		return new String[0];
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:FacesRequestAttributes.java

示例10: listarProvaAvaliador

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
public void listarProvaAvaliador() {
	zerarLista();
	FacesContext fc = FacesContext.getCurrentInstance();
	ExternalContext ec = fc.getExternalContext();
	HttpSession session = (HttpSession) ec.getSession(false);
	Usuario usuariologado=(Usuario)session.getAttribute("usuario");
	if (parecerProvaFiltrada != null && !parecerProvaFiltrada.isEmpty()) {
		list.addAll(dao.findByNameAvaliador(parecerProvaFiltrada,usuariologado));
	} else {
		list.addAll(dao.findAllAvaliador(usuariologado));
	}
}
 
开发者ID:IsadoraScusselFarias,项目名称:ProjetoFinalInitium,代码行数:13,代码来源:ProvaBean.java

示例11: registraSaida

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
public String registraSaida() {
	FacesContext fc = FacesContext.getCurrentInstance();
	ExternalContext ec = fc.getExternalContext();
	HttpSession session = (HttpSession) ec.getSession(false);
	session.removeAttribute("usuario");

	return "/login";
}
 
开发者ID:IsadoraScusselFarias,项目名称:ProjetoFinalInitium,代码行数:9,代码来源:AutenticacaoBean.java

示例12: validaUsuario

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
private void validaUsuario(final String destino) {
	try {
   		Pessoa pessoa = pessoaService.validarUsuario(loginUser, senhaUser);
   		System.out.println("Usuario logado: " + pessoa.getNome());
   		
   		final ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext(); 
   		final HttpSession session = (HttpSession) ec.getSession(true);
		session.setAttribute("usuario", pessoa);
		//session.setAttribute("pessoa", pessoa);
		
		ec.redirect(ec.getRequestContextPath() + destino);
	} catch (Exception e) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Mensagem:", "Usuário ou senha invalido!"));
	}
}
 
开发者ID:kashm1r,项目名称:photoiff,代码行数:16,代码来源:ValidarBean.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

示例15: getSessionMutex

import javax.faces.context.ExternalContext; //导入方法依赖的package包/类
/**
 * Return the best available mutex for the given session:
 * that is, an object to synchronize on for the given session.
 * <p>Returns the session mutex attribute if available; usually,
 * this means that the HttpSessionMutexListener needs to be defined
 * in {@code web.xml}. Falls back to the Session reference itself
 * if no mutex attribute found.
 * <p>The session mutex is guaranteed to be the same object during
 * the entire lifetime of the session, available under the key defined
 * by the {@code SESSION_MUTEX_ATTRIBUTE} constant. It serves as a
 * safe reference to synchronize on for locking on the current session.
 * <p>In many cases, the Session reference itself is a safe mutex
 * as well, since it will always be the same object reference for the
 * same active logical session. However, this is not guaranteed across
 * different servlet containers; the only 100% safe way is a session mutex.
 * @param fc the FacesContext to find the session mutex for
 * @return the mutex object (never {@code null})
 * @see org.springframework.web.util.WebUtils#SESSION_MUTEX_ATTRIBUTE
 * @see org.springframework.web.util.HttpSessionMutexListener
 */
public static Object getSessionMutex(FacesContext fc) {
	Assert.notNull(fc, "FacesContext must not be null");
	ExternalContext ec = fc.getExternalContext();
	Object mutex = ec.getSessionMap().get(WebUtils.SESSION_MUTEX_ATTRIBUTE);
	if (mutex == null) {
		mutex = ec.getSession(true);
	}
	return mutex;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:FacesContextUtils.java


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