Wednesday, August 20, 2014

IE 11 problem workaround - file names messed up

Note: patch 18277370 needed for to run ie 11

All our download links on ie 11 file names looked like they have been url encoded something like:


Really irritating for our users so the quick and dirty for now was to modify (luckily all our download code is common) our download method to reset the headers on the response.

On our button we add the following:
<af:fileDownloadActionListener filename="test.txt"

And we add a property to the request that contains the ucm path like such:
  <af:setPropertyListener from="/ucm/path/here"

    public void startDownload(FacesContext facesContext, OutputStream outputStream) {
        String docName = (String)JSFUtils.getFromRequest("ucmCurrentDocument");
 ... write file to output stream here ...

    private void applyIE11Fix(String docName) {
        RequestContext requestCtx = RequestContext.getCurrentInstance();
        Agent agent = requestCtx.getAgent();
        String version = agent.getAgentVersion();
        String browser = agent.getAgentName();

        //if ie 11
        if (browser != null && "ie".equals(browser) && version != null && version.startsWith("11")) {

            HttpServletResponse resp = JSFUtils.getResponse();
            String finalName = docName;

            try {
                finalName = URLEncoder.encode(docName, "UTF-8");
            } catch (UnsupportedEncodingException e) {

            resp.setHeader("content-disposition", "attachment; filename=\"" + finalName + "\"");