get Session Param from JSF FacesContext - Java JSF

Java examples for JSF:Session

Description

get Session Param from JSF FacesContext

Demo Code


import java.util.Map;
import java.util.Map.Entry;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

public class Main{
    public static void main(String[] argv) throws Exception{
        String name = "java2s.com";
        System.out.println(getSessionParam(name));
    }/*from  ww  w.  ja va2 s.  c om*/
    public static Object getSessionParam(String name) {
        Map<String, Object> map = FacesContext.getCurrentInstance()
                .getExternalContext().getSessionMap();
        for (Entry<String, Object> entry : map.entrySet()) {
            if (name.equals(entry.getKey())) {
                return entry.getValue();
            }
        }
        return null;
    }
}

Related Tutorials