Thanks for the quick response. I followed your suggestion and extended AbstractView.
For anyone else who comes across this problem this is how I fixed it:
Servlet config, notice the order=1, thats what makes all this work
Code:
<!-- Resolves the pdf view to a PDF document -->
<bean id="pdfViewResolver" class="view.PDFViewResolver">
<property name="order" value="1" />
</bean>
<!-- Resolves flow view names to .jsp templates -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
<property name="order" value="2" />
</bean>
My flow definition:
Code:
<view-state id="indexView" view="index">
<transition on="submit" to="pdfRenderer"/>
</view-state>
<view-state id="pdfRenderer" view="pdf">
<render-actions>
<action bean="action" method="renderPDF"/>
</render-actions>
</view-state>
My action class:
Code:
public Event renderPDF(RequestContext ctx) {
byte[] file = getFileFromWebService();
ctx.getFlashScope().put("file", file);
return success();
}
My View class:
Code:
public class PDFView extends AbstractView {
@Override
protected final void renderMergedOutputModel(
Map model, HttpServletRequest request, HttpServletResponse response) throws Exception {
byte[] file = (byte[])model.get("file");
if(null == file) {
System.err.println("File is NULL");
}
response.setContentType("application/pdf);
response.setContentLength(file.length);
response.setHeader("Content-disposition", "inline;filename=file.pdf");
response.setHeader("Cache-Control", "cache");
response.addHeader("Cache-Control", "must-revalidate");
response.setHeader("Pragma", "public");
ServletOutputStream out = response.getOutputStream();
out.write(file);
out.flush();
}
And lastly my View Resolver:
Code:
public class PDFViewResolver extends AbstractCachingViewResolver implements Ordered {
@Override
protected View loadView(String viewName, Locale local) throws Exception {
if (viewName != null) {
if ("pdf".equals(viewName)) {
logger.debug("Creating an PDFView for view name " + viewName);
return new PDFView();
}
}
return null;
}
Thanks @dr_pompeii