6

Hi I am working on a JSF project, I will like to access some session level variables onto my xhtml UI pages directly without using any managed bean.

Just wanted to know if this is possible and if yes than how?

Thanks

NKS
  • 1,140
  • 4
  • 17
  • 35
  • 1
    The way to go is using a `@SessionScoped` bean to store them. Then, you can access it from the view. – Aritz Oct 18 '13 at 09:12
  • Do you know how to get [HTTP session](http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpSession.html)? Do you know how to [set its attributes](http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpSession.html#setAttribute(java.lang.String, java.lang.Object))? Have you checked [`ExternalContext`](http://docs.oracle.com/javaee/6/api/javax/faces/context/ExternalContext.html) documentatuion? – skuntsel Oct 18 '13 at 09:18
  • possible duplicate of [How can I access session attribute in Facelets page](http://stackoverflow.com/questions/13047446/how-can-i-access-session-attribute-in-facelets-page) – Aritz Oct 18 '13 at 09:50

1 Answers1

11

Yes its possible

If the bean doesnot exits then put it in session first

FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key,object);

And to use the bean on xhtml page use

<h:outputText value="#{sessionScope.key}" /> 
BholaVishwakarma
  • 581
  • 6
  • 18