javaee.module.webapp.utilities.FacesSessionUtility Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-javaee-module Show documentation
Show all versions of common-javaee-module Show documentation
This Module contains common JavaEE Helper Classes.
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 );
}
}