2016-08-15 5 views
0

後primefaces DocumentViewerの復元:私はこのようなprimefaces-拡張子からDocumentViewerの成分を使用しているページのリロード

<pe:documentViewer cache="true" value="#{myBean.streamedContent}"/> 

MyBeanとはSessionScopedです。

getterが呼び出され、streamedContentが空ではなく、ビューアに空のページとメッセージstream must have dataが表示されます。

ページの再読み込み時にビューアで文書を復元するにはどうすればよいですか?

答えて

1

私はPrimeFaces Extensions Showcaseを使用して、問題を再現しましたので、私はコードの下に

ByteArrayOutputStream out = new ByteArrayOutputStream(); 

Document document = new Document(); 
PdfWriter.getInstance(document, out); 
document.open(); 

for (int i = 0; i < 50; i++) { 
     document.add(new Paragraph("All work and no play makes Jack a dull boy")); 
} 

document.close(); 
content = new DefaultStreamedContent(new ByteArrayInputStream(out.toByteArray()), "application/pdf"); 

を使用しかし、私は解決策を見つけました。問題はDefaultStreamedContentのみを使用していますが、階層を確認したところでByteArrayContentを使用する可能性もあることがわかりました。ページのリロード後も機能します。

使用例:

content = new ByteArrayContent(out.toByteArray(), "application/pdf"); 
関連する問題