io.github.rongaru.javaee.utilities.FacesManagedBeanUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javaee Show documentation
Show all versions of javaee Show documentation
Java Classes For JavaEE JSF.
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