file downloading error with IE7

Hi,

I'm trying to execute the function in my backing bean

ByteArrayOutputStream stream = new ByteArrayOutputStream();

createExcelFile(stream);

HttpServletResponse response = (HttpServletResponse) faces

.getExternalContext().getResponse();

response.setContentType("application/vnd.ms-excel");

response.setContentLength(stream.size());

response.setHeader("Content-disposition",

"inline; filename=\"Timesheet.xsl\"");

try {

ServletOutputStream out;

out = response.getOutputStream();

out.write(stream.toByteArray());

faces.responseComplete();

} catch (IOException e) {

e.printStackTrace();

}

Everything is great when I save the file, but when I open it in IE7 directly I can see all the xls content but I have error message in my Tomcat console window:

javax.servlet.jsp.JspException: Cannot find FacesContext

at javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:427)

at com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:125)

..................................

The problem is the following:

Request:

POST /Portal/index.jsf HTTP/1.1

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*

Referer: http://localhost:88/Portal/index.jsf?as=timesheetList

Accept-Language: en-us

Content-Type: application/x-www-form-urlencoded

UA-CPU: x86

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)

Host: localhost:88

Content-Length: 235

Connection: Keep-Alive

Cache-Control: no-cache

Cookie: JSESSIONID=4349FF698370ACC8C69A20545A4ECDED

com.sun.faces.VIEW=_id46%3A_id47&TimesheetTemplate%3ATimesheetTemplateForm=TimesheetTemplate%3ATimesheetTemplateForm&TimesheetTemplate%3ATimesheetTemplateForm%3A_idcl=TimesheetTemplate%3ATimesheetTemplateForm%3A_id3%3A0%3A_id11&as=nullOPTIONS /Portal/ HTTP/1.1

User-Agent: Microsoft Office Protocol Discovery

Host: localhost:88

Content-Length: 0

Connection: Keep-Alive

After that I can download the file - it's ok.

When xls file is opened in IE7 window I see the expected xls content but

IE7 sends two additional requests and they

cause the error message:

Cannot find FacesContext - which is true because nothing is availabe. Is any way to exclude HTTP OPTIONS form jsf?

)

OPTIONS /Portal/ HTTP/1.1

User-Agent: Microsoft Office Protocol Discovery

Host: localhost:88

Content-Length: 0

Connection: Keep-Alive

OPTIONS /Portal/ HTTP/1.1

User-Agent: Microsoft Office Protocol Discovery

Host: localhost:88

Content-Length: 0

Connection: Keep-Alive

[2970 byte] By [alextmna] at [2007-11-26 21:38:15]
# 1

faces.responseComplete(); appears to be your only reference

to to the Faces servlet in your bean of you do not appear to have

obtained the faces context either for that point.

As for the "backing beans" disposition as a servlet and the

new servlet wrapped/nested inside to use for a download

stream for the file i don't say that is a problem and independent

of the Faces Context. Backing beans require to be managed

and have property values property-value that can be set as

null with a special nulling empty element and require the typing

of the property also.

Try this also ......"Attachment; filename=\"Timesheet.xsl\"");

nicephotoga at 2007-7-10 3:21:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
How are you invoking the download?This article might give you some new insights: http://balusc.xs4all.nl/srv/dev-jep-pdf.html
BalusCa at 2007-7-10 3:21:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

This is how I invoke the bean:

<h:commandLink value="Excel" immediate="true"

actionListener="#{timesheetManager.doExportExcel}" />

before go to the snippet i do

FacesContext faces = FacesContext.getCurrentInstance();

My question is why IE6 sends HTTP OPTION, while Mozilla and Opera does not

alextmna at 2007-7-10 3:21:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Attachment; filename=\"Timesheet.xls\" works great

inline opens the XSL file in the same IE7 (get excel as ActiveX) window but Attachment opens excel app and the file is there.

I have created simple project with export only for Inline option and get the same bug.

Even for me Attachment is ok , but jsf should support Inline as well, that's what I think

Thanks for the help

alextmna at 2007-7-10 3:21:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Read these, they contain the request response ifo

about resouces.

HTTP OPTION

http://www.ietf.org/rfc/rfc1945.txt

RFC 1945HTTP/1.0[page 6]

http://www.ietf.org/rfc/rfc2068.txt

Hypertext Transfer Protocol -- HTTP/1.1

9.2 OPTIONS

(...i got a copy of em for myself ...hmmm).

A like to using AJAX the overall system is layers of control

protocols and inside they have commands. It seems some

of this may be the server type in use and the retrieved

information by the isp hops possibly find an odd

configuration requiring the want for a clearer set of

parameters,maybe?

nicephotoga at 2007-7-10 3:21:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...