Can we access session scope variables directly in

2019-04-28 03:40发布

问题:

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

回答1:

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}" />