Hello Helmut,

just solved see:

http://issues.apache.org/jira/browse/TOBAGO-303

Should be available with the next nightly build

Regards


Bernd

H. Swaczinna wrote:
Hi,

I've a page with a link to download a PDF file. The PDF download itself
works without a problem. But after a download Ajax requests don't work
anymore, for example a popup or a tabGroup with reloadTab.

Here's a small testcase for this behavior.

The page:

<%@ taglib uri="http://myfaces.apache.org/tobago/component"; prefix="tc" %><%@ taglib uri="http://java.sun.com/jsf/core"; prefix="f" %><%@ page contentType="text/html;charset=UTF-8" language="java" %><%@ page pageEncoding="UTF-8" %><f:view
 ><tc:page id="testPage" width="300px" height="200px">
    <tc:panel>
      <f:facet name="layout">
<tc:gridLayout cellspacing="0" rows="fixed;fixed"/>
      </f:facet>
      <tc:link id="pdfLink"
        label="PDF"
        immediate="true"
        transition="false"
        actionListener="#{anlagenController.showPDFActionListener}">
        <f:attribute name="file" value="test1.pdf"/>
      </tc:link>
      <tc:link id="ajaxLink"
        label="Ajax">
        <tc:attribute name="renderedPartially" value="testPopup"/>
        <f:facet name="popup">
          <tc:popup id="testPopup" width="300" height="200">
<tc:button id="closeButton" label="Close">
              <tc:attribute name="popupClose" value="immediate"/>
            </tc:button>
          </tc:popup>
        </f:facet>
      </tc:link>
    </tc:panel>
  </tc:page>
</f:view>

The java code for the PDF download:

  public void showPDFActionListener(ActionEvent e) {
    String filename = (String)e.getComponent().getAttributes().get("file");
    sendFile(attachmentPath, filename, "application/pdf");
  }

  protected void sendFile(String filepath, String filename, String mimeType) {
    File file = new File(filepath, filename);
    if (file.exists() && file.isFile()) {
      try {
        InputStream in = new FileInputStream(file);
        FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)facesContext.getExternalContext().getResponse();
        response.setContentType(mimeType);
        response.setContentLength(in.available());
response.setHeader("Content-disposition", " attachment;filename=\"" + filename + "\"");
        ServletOutputStream out = response.getOutputStream();
        byte[] buffer = new byte[0x10000];
        while (in.read(buffer) > 0) {
          out.write(buffer);
        }
        in.close();
out.close(); StateManager stateManager = (StateManager)facesContext.getApplication().getStateManager(); stateManager.saveSerializedView(facesContext); facesContext.responseComplete();
      } catch (Exception x) {
        getLog().error("Error writing output", x);
      }
    } else {
      getLog().error("File " + file.getAbsolutePath() + " not found");
    }
  }
I think there's a problem with Ajax when a page submit has no result.

Regards
Helmut

Reply via email to