Java Code Examples for javax.faces.context.ExternalContext#getSession()

The following examples show how to use javax.faces.context.ExternalContext#getSession() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FacesWebRequest.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example 2
Source File: FacesWebRequest.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 3
Source File: FacesWebRequest.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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();
}
 
Example 4
Source File: FacesWebRequest.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example 5
Source File: FacesRequestAttributes.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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);
	}
}
 
Example 6
Source File: MessageForumsNavigationHandler.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Handle the navigation
 * 
 * @param context
 *        The Faces context.
 * @param fromAction
 *        The action string that triggered the action.
 * @param outcome
 *        The logical outcome string, which is the new tool mode, or if null, the mode does not change.
 */
public void handleNavigation(FacesContext context, String fromAction, String outcome)
{
	m_chain.handleNavigation(context, fromAction, outcome);		
	
	ExternalContext exContext = context.getExternalContext();
   HttpSession session = (HttpSession) exContext.getSession(false);

   if (session == null){
     return;
   }
	
	// add previous navigationString (outcome) to session
	session.setAttribute("MC_PREVIOUS_NAV", outcome);
}
 
Example 7
Source File: FacesRequestAttributes.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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];
	}
}
 
Example 8
Source File: FacesRequestAttributes.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 9
Source File: FacesRequestAttributes.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 10
Source File: FacesRequestAttributes.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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;
	}
}
 
Example 11
Source File: FacesRequestAttributes.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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];
	}
}
 
Example 12
Source File: MessageForumsNavigationHandler.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Handle the navigation
 * 
 * @param context
 *        The Faces context.
 * @param fromAction
 *        The action string that triggered the action.
 * @param outcome
 *        The logical outcome string, which is the new tool mode, or if null, the mode does not change.
 */
public void handleNavigation(FacesContext context, String fromAction, String outcome)
{
	m_chain.handleNavigation(context, fromAction, outcome);		
	
	ExternalContext exContext = context.getExternalContext();
   HttpSession session = (HttpSession) exContext.getSession(false);

   if (session == null){
     return;
   }
	
	// add previous navigationString (outcome) to session
	session.setAttribute("MC_PREVIOUS_NAV", outcome);
}
 
Example 13
Source File: FacesRequestAttributes.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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;
	}
}
 
Example 14
Source File: FacesRequestAttributes.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object getSessionMutex() {
	// Enforce presence of a session first to allow listeners to create the mutex attribute
	ExternalContext externalContext = getExternalContext();
	Object session = externalContext.getSession(true);
	Object mutex = externalContext.getSessionMap().get(WebUtils.SESSION_MUTEX_ATTRIBUTE);
	if (mutex == null) {
		mutex = (session != null ? session : externalContext);
	}
	return mutex;
}
 
Example 15
Source File: FacesRequestAttributes.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Object getSessionMutex() {
	// Enforce presence of a session first to allow listeners to create the mutex attribute
	ExternalContext externalContext = getExternalContext();
	Object session = externalContext.getSession(true);
	Object mutex = externalContext.getSessionMap().get(WebUtils.SESSION_MUTEX_ATTRIBUTE);
	if (mutex == null) {
		mutex = (session != null ? session : externalContext);
	}
	return mutex;
}
 
Example 16
Source File: FacesRequestAttributes.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Object getSessionMutex() {
	// Enforce presence of a session first to allow listeners to create the mutex attribute
	ExternalContext externalContext = getExternalContext();
	Object session = externalContext.getSession(true);
	Object mutex = externalContext.getSessionMap().get(WebUtils.SESSION_MUTEX_ATTRIBUTE);
	if (mutex == null) {
		mutex = (session != null ? session : externalContext);
	}
	return mutex;
}
 
Example 17
Source File: FacesContextUtils.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * 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
 */
@Nullable
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;
}
 
Example 18
Source File: FacesContextUtils.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example 19
Source File: FacesContextUtils.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example 20
Source File: FacesContextUtils.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * 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
 */
@Nullable
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;
}