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

io.github.rongaru.javaee.utilities.FacesManagedBeanUtils Maven / Gradle / Ivy

The newest version!
package io.github.rongaru.javaee.utilities;

import javax.faces.context.FacesContext;

public abstract class FacesManagedBeanUtils {

	public static < T > T removeSessionManagedBean( Class< T > element ) {
		String identifier = getManagedBeanIdentifier( element );
		return ( T ) removeSessionManagedBean( identifier );
	}

	public static < T > T createSessionManagedBean( Class< T > element ) {
		String identifier = getManagedBeanIdentifier( element );
		return ( T ) createSessionManagedBean( identifier );
	}

	public static Object removeSessionManagedBean( String element ) {
		return FacesSessionUtils.getSessionParameters( ).remove( element );
	}

	public static Object createSessionManagedBean( String element ) {
		String identifier = "#{" + element + "}";
		FacesContext context = FacesContext.getCurrentInstance( );
		return context.getApplication( ).createValueBinding( identifier ).getValue( context );
	}

	protected static < T > String getManagedBeanIdentifier( Class< T > element ) {
		String className = element.getSimpleName( );
		char c = Character.toLowerCase( className.charAt( 0 ) );
		StringBuilder identifierBuilder = new StringBuilder( "" + c );
		className.chars( ).skip( 1 ).forEach( identifierBuilder :: append );
		return identifierBuilder.toString( );
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy