Skip to main content

JSF issues with loading pdf file inline ...

No replies
jasonwang8
Offline
Joined: 2012-01-26
Points: 0

I am trying to migrate from JSF 1.1 to JSF 1.2 / 2.0 and running into the following exception:

java.nio.charset.MalformedInputException: Input length = 1
	java.nio.charset.CoderResult.throwException(CoderResult.java:260)
	java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:781)
	com.sun.faces.application.ByteArrayWebOutputStream.writeTo(ByteArrayWebOutputStream.java:112)
	com.sun.faces.application.ViewHandlerResponseWrapper.flushToWriter(ViewHandlerResponseWrapper.java:162)
	com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:220)
	org.springframework.faces.webflow.FlowViewHandler.renderView(FlowViewHandler.java:99)
	com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:532)
	org.springframework.faces.webflow.FlowViewHandler.renderView(FlowViewHandler.java:99)
	com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
	com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
	com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
	javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
	org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	com.fss.util.CharsetFilter.doFilter(CharsetFilter.java:40)
The jsp file is as follows:

<%@page import="java.io.BufferedOutputStream" %>

<%

byte[] ss = (byte[]) getServletContext().getAttribute("ALERTS_PDF_EXPORT_DATA");
getServletContext().removeAttribute("ALERTS_PDF_EXPORT_DATA");

String fileName = (String) session.getAttribute("ALERTS_PDF_FILE_NAME");

session.removeAttribute("ALERTS_PDF_EXPORT");
session.removeAttribute("ALERTS_PDF_FILE_NAME");
if(fileName==null || fileName.length()==0) fileName = "AlertsReport.pdf";
response.setStatus( 200);
response.setContentType("application/pdf;charset=utf-8");
response.setHeader("Content-Disposition","inline;filename="+fileName);
response.setHeader("Cache-Control","no-cache");
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
bos.write(ss); ///// this is line cause the problem.
out.clear();
out = pageContext.pushBody();
bos.close();
%>


JSF 1.1 works. I don't have the source code. so not sure why it works.

It seems JSF 2.x have the same implementation.


Thank you in advance for your kind help!

Jason