Reputation:
Is it somehow possible to accesse a sesssion-scoped bean in a class extending the GenericFacesPortlet
?
Is a portlet even aware of the FacesContext
?
What do I want to achieve?
I want to serve a file through the serveResource()
method. The file's content should be retrieved from a bean implementing the method getResourceContent()
.
But unfortunately, I'm getting null
when calling FacesContext.getCurrentInstance()
.
For your information: I'm using the JBoss Portlet Bridge in Version 2.1.0.FINAL.
Upvotes: 3
Views: 915
Reputation: 38
The FacesContext will always be null in the GenericFacesPortlet. The GenericFacesPortlet creates the bridge and initializes it. The Bridge is actually creating the FacesContext and executing the JSF life cycle. From your GenericFacesPortlet point of view the FacesContext is not yet created (null).
In order to achieve what you want, you can grab the bean from the session. In order to do that you must use:
YourBean yourBean = (YourBean) request.getPortletSession().getAttribute("yourBeanName");
where "yourBeanName" is the name you used in the faces-config.xml when you defined YourBean.
Cheers!
Upvotes: 1