3

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.

4

1 回答 1

1

FacesContext 在 GenericFacesPortlet 中始终为空。GenericFacesPortlet 创建桥并对其进行初始化。Bridge 实际上是创建 FacesContext 并执行 JSF 生命周期。从您的 GenericFacesPortlet 的角度来看,FacesContext 尚未创建(空)。

为了实现你想要的,你可以从会话中抓取 bean。为此,您必须使用:

YourBean yourBean = (YourBean) request.getPortletSession().getAttribute("yourBeanName");

其中“yourBeanName”是您在定义 YourBean 时在 faces-config.xml 中使用的名称。

干杯!

于 2011-11-25T17:25:43.203 回答