<p:graphicImage>
की तरह, value
विशेषता StreamedContent
पर लौटने वाली बीन संपत्ति को इंगित कर सकती है। डेटाबेस के गतिशील संसाधन के साथ <p:graphicImage>
का उपयोग करने पर निम्नलिखित उत्तरों में विस्तार से बताए गए कारणों के लिए केवल एक विशेष गेटर विधि की आवश्यकता है: Display dynamic image from database with p:graphicImage and StreamedContent।
अपने विशिष्ट उदाहरण में, यह इस तरह दिखेगा:
<p:media value="#{mediaManager.stream}" width="100%" height="300px" player="pdf">
<f:param name="id" value="#{bean.mediaId}" />
</p:media>
साथ
@ManagedBean
@ApplicationScoped
public class MediaManager {
@EJB
private MediaService service;
public StreamedContent getStream() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
// So, we're rendering the HTML. Return a stub StreamedContent so that it will generate right URL.
return new DefaultStreamedContent();
} else {
// So, browser is requesting the media. Return a real StreamedContent with the media bytes.
String id = context.getExternalContext().getRequestParameterMap().get("id");
Media media = service.find(Long.valueOf(id));
return new DefaultStreamedContent(new ByteArrayInputStream(media.getBytes()));
}
}
}
क्या होगा यदि मैं @ViewScoped में मेरी ManagedBean रहते हैं? –