jsf - How to bind dynamic content using <p:media>? -
i use <p:media>
display static pdf content.
<p:media value="/resource/test.pdf" width="100%" height="300px" player="pdf"> </p:media>
how can change display dynamic content?
like in <p:graphicimage>
, value
attribute can point bean property returning streamedcontent
. requires special getter method reasons explained in detail in following answer on using <p:graphicimage>
dynamic resource database: display dynamic image database p:graphicimage , streamedcontent.
in particular example, this:
<p:media value="#{mediamanager.stream}" width="100%" height="300px" player="pdf"> <f:param name="id" value="#{bean.mediaid}" /> </p:media>
with
@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 html. return stub streamedcontent generate right url. return new defaultstreamedcontent(); } else { // so, browser requesting media. return real streamedcontent media bytes. string id = context.getexternalcontext().getrequestparametermap().get("id"); media media = service.find(long.valueof(id)); return new defaultstreamedcontent(new bytearrayinputstream(media.getbytes())); } } }
Comments
Post a Comment