Remove a JSF Bean from the application map. - Java JSF

Java examples for JSF:FacesContext

Description

Remove a JSF Bean from the application map.

Demo Code

/**//from w  w  w. j  a  v a2 s .  co  m
 * License: src/main/resources/license/escidoc.license
 */
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.apache.log4j.Logger;

public class Main{
    public static void main(String[] argv) throws Exception{
        Class cls = String.class;
        removeBeanFromMap(cls);
    }
    /**
     * Remove a Bean from the application map. Can be used to force a bean to be reinitialized
     * 
     * @param cls
     */
    public static synchronized void removeBeanFromMap(final Class<?> cls) {
        String name = cls.getSimpleName();
        Object result = FacesContext.getCurrentInstance()
                .getExternalContext().getApplicationMap().get(name);
        if (result != null)
            FacesContext.getCurrentInstance().getExternalContext()
                    .getApplicationMap().remove(name);
    }
}

Related Tutorials