All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javaee.module.webapp.utilities.FacesSessionUtility Maven / Gradle / Ivy

The newest version!
package javaee.module.webapp.utilities;

import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

public abstract class FacesSessionUtility {

	public static Map< String, Object > getSessionParameters( ) {
		FacesContext context = FacesContext.getCurrentInstance( );
		return context.getExternalContext( ).getSessionMap( );
	}

	public static Iterator< FacesMessage > getMessagesIterator( ) {
		FacesContext context = FacesContext.getCurrentInstance( );
		return context.getMessages( );
	}

	public static void saveMessagesToContext( List< FacesMessage > messages ) {
		FacesContext context = FacesContext.getCurrentInstance( );
		messages.forEach( message -> context.addMessage( null, message ) );
	}

	public static HttpSession getCurrentUserHttpSession( boolean shouldCreateNew ) {
		FacesContext context = FacesContext.getCurrentInstance( );
		ExternalContext externalContext = context.getExternalContext( );
		return ( HttpSession ) externalContext.getSession( shouldCreateNew );
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy