I am trying to write a controller that generates a CSV spreadsheet to save as a file.
I have written the following action and render methods
/**
* Get the stats for the search.
*/
@ActionMapping(params={"controller=exportView","action=csv"})
public void viewInstance(ActionRequest request, ActionResponse response){
response.setRenderParameter("controller", "exportView");
response.setRenderParameter("action","csv");
}
@RenderMapping(params={"controller=exportView","action=csv"})
public String viewInstance(@RequestParam(value = "id", required = true) final String viewInstanceId, RenderRequest request, RenderResponse response, Model model) throws Exception {
ApplicationContext ctx = ThreadApplicationContextHolder.getApplicationContext();
.. do some stuff
String filename = getFilename();
response.setContentType("text/csv"); // go bang here
response.addProperty(ExportViewInstanceAsCsvFileController.HEADER_CONTENT_DISPOSITION, "attachment;filename=" + filename + ExportViewInstanceAsCsvFileController.FILE_EXT);
viewInstanceFileRenderer.renderSearchResultNodesToFile(getData(), response.getPortletOutputStream());
return "portlet/exportView";
}
When it runs the server complains that the content type is not "text/html", so I amended the portlet.xml to have
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<supports>
<mime-type>text/csv</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
but websphere seems to be ignoring this.
When I debug and run request.getResponseContentTypes()
it only has text/html
in the collection. The application structure has a portlet to handle logons and then
three web applications to handle various aspects of the application. I have modified the
portlet in the web application that handles the spreadsheet generation, but not in the logon portlet.
My next step is to change that(the logon portlet.xml) but I am not confident it will work.
Are there any other places I can look?