问题
I use the media primefaces tag to present pdf's but if the bean is @ViewScope
the stream is always null, why?
回答1:
Because the desired JSF view state isn't available when the webbrowser is about to download the PDF in an entirely separate(!!) HTTP request. This is essentially exactly the same problem as with PrimeFaces <p:graphicImage>
as answered in the following questions:
- How to bind dynamic content using <p:media>?
- Display dynamic image from database with p:graphicImage and StreamedContent
Basically, you need to pass an identifier of the desired media file as <f:param>
and then create an entirely stateless managed bean which streams the desired DefaultStreamedContent
depending on the current request phase ID and the supplied request parameter.
来源:https://stackoverflow.com/questions/25424713/why-primefaces-media-dynamic-doesnt-work-in-view-scope