在尝试从FacesContext获取ResponseWriter时,在Seam中获取NullPointerException

时间:2022-11-15 19:58:03

I am working on a Seam app. I am trying to get the ResponseWriter from the FacesContext, but I get a NullPointerException.

我正在开发一个Seam应用程序。我试图从FacesContext获取ResponseWriter,但我得到一个NullPointerException。

I can get a FacesContext by calling

我可以通过调用获得FacesContext

FacesContext context = FacesContext.getCurrentInstance();

According to the debugger, the responseWriter variable in the FacesContext object is null, so calling

根据调试器,FacesContext对象中的responseWriter变量为null,因此调用

ResponseWriter writer = context.getResponseWriter();

gives a NullPointerException.

给出一个NullPointerException。

Why would the ResponseWriter be null? Is it null by default? We can get it from a FacesContext in plenty of other places in our code.

为什么ResponseWriter为null?默认为空吗?我们可以在代码中的很多其他地方从FacesContext中获取它。

Is there a way I can set it manually?

有没有办法我可以手动设置它?

1 个解决方案

#1


0  

I think this is similar to the problem I was getting recently. I tried to use the Excel-writing api within Seam to programmatically generate an Excel file, rather than using an xhtml template with specific tags.

我认为这与我最近遇到的问题类似。我尝试在Seam中使用Excel编写API以编程方式生成Excel文件,而不是使用带有特定标记的xhtml模板。

While this worked in older versions of Seam, using the 2.2.0 meant that I couldn't get a Writer from the context to pass to the constructor of the Workbook.

虽然这在旧版本的Seam中有效,但使用2.2.0意味着我无法从上下文中获取Writer来传递给Workbook的构造函数。

Sadly, I never found a solution, so I'm not sure there is a solution to this.

可悲的是,我从来没有找到解决方案,所以我不确定是否有解决方案。

#1


0  

I think this is similar to the problem I was getting recently. I tried to use the Excel-writing api within Seam to programmatically generate an Excel file, rather than using an xhtml template with specific tags.

我认为这与我最近遇到的问题类似。我尝试在Seam中使用Excel编写API以编程方式生成Excel文件,而不是使用带有特定标记的xhtml模板。

While this worked in older versions of Seam, using the 2.2.0 meant that I couldn't get a Writer from the context to pass to the constructor of the Workbook.

虽然这在旧版本的Seam中有效,但使用2.2.0意味着我无法从上下文中获取Writer来传递给Workbook的构造函数。

Sadly, I never found a solution, so I'm not sure there is a solution to this.

可悲的是,我从来没有找到解决方案,所以我不确定是否有解决方案。