當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。