0

これは、次の質問の正確なコピーです: How to provide a file download from a JSF backing Bean?

別の顔を使用しようとしているのとは別に、説明されている方法は機能しません。

注:使えません

使用時 - ファイルのダウンロードは正常に行われます。

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">

使用しようとしていますが、ページが更新されるだけです。リクエストに対して ajax が有効になっているかどうかはわかりませんが、回答に記載されているメソッドが機能しません。

オブジェクトのコードは次のとおりです。

<af:commandMenuItem text="Test" id="cmi2389"
                rendered="true"
                actionListener="#{pageFlowScope.InkassPorReportBean.dlw}"
                partialSubmit="false" immediate="true">
</af:commandMenuItem>

コンテンツの長さをファイル サイズに設定すると、次のエラーも発生します。応答サイズが設定されていない場合、これは発生しません。

<Jun 9, 2015 7:37:14 PM MSK> <Error> <HTTP> <BEA-101083> <Connection failure.
java.net.ProtocolException: Didn't meet stated Content-Length, wrote: '0' bytes instead of stated: '-1' bytes.
    at weblogic.servlet.internal.ServletOutputStreamImpl.ensureContentLength(ServletOutputStreamImpl.java:463)
> 

<Jun 9, 2015 7:37:14 PM MSK> <Error> <HTTP> <BEA-101104> <Servlet execution in servlet context "ServletContext@1243894494[app:sxdocs_XversionX module:sxdocs_XversionX path:null spec-version:3.0]" failed, java.net.ProtocolException: Didn't meet stated Content-Length, wrote: '0' bytes instead of stated: '-1' bytes..
java.net.ProtocolException: Didn't meet stated Content-Length, wrote: '0' bytes instead of stated: '-1' bytes.
    at weblogic.servlet.internal.ServletOutputStreamImpl.ensureContentLength(ServletOutputStreamImpl.java:463)
>

リクエストが発行されました:

POST /sxdocs_XversionX/faces/main.jsf?Adf-Window-Id=w0&Adf-Page-Id=1 HTTP/1.1

pageFlowScope.InkassPorReportBean.dlw: は、別の質問への回答に示されているように、ファイル ダウンロード手順を実行するバッキング Bean のアクション リスナー メソッドです。

4

1 に答える 1

0

次のようなfileDownloadActionListenerを使用する必要があります。

< af:commandMenuItem ...
    <af:filedownloadactionlistener contenttype="application/octet-stream"
                method="#{backingBean.doDownload}"  filename="defaultFilename.txt"/>           
</af:commandMenuItem >

 public void doDownload(FacesContext facesContext, OutputStream outputStream) {
      // write the neccessary code to get the download data from the Model
      String data = getDownloadData();

      // save to the output stream
      try {
          OutputStreamWriter writer = new OutputStreamWriter(outputStream,"UTF-8");
           writer.write(data);
           writer.close();
          outputStream.close();
      } catch (IOException e) {
          // handle I/O exceptions
      }
  }

その他の参照:

http://adfcodebits.blogspot.co.uk/2010/06/bit-19-downloading-file.html https://tompeez.wordpress.com/2011/11/26/jdev11-1-2-1-0 -handling-imagesfiles-in-adf-part-2/

于 2015-06-09T15:58:57.090 に答える