How can we embed and show an InputStream
as dynamic image in JSF 2.0 with OmniFaces?
相关问题
- Infinite setStatus() loop when requesting a JSF pa
- JSF2 composite cc.attrs expression does not evalua
- How to address the surrounding naming container in
- Generate p:tabs from Java List
- Omit validation for p:selectOneMenu, for Ajax requ
相关文章
- Will closing a DataInputStream also close the File
- CipherInputStream is Empty when trying to decrypt
- Read pdf uploadstream one page at a time with java
- change rendered attribute from managed bean
- How to show confirm (richfaces) popup when
- How to override primefaces component api class wit
- JPA lazy loading Collections in JSF view - better
- How to design a session-less JSF 2.0 web applicati
OmniFaces does not offer any utility for this — yet.
If the image files are located on the disk file system, then you need to create a virtual context in the servletcontainer configuration so that they can be accessed by a normal URL. See also Load images from outside of webapps / webcontext / deploy folder using <h:graphicImage> or <img> tag.
If the image files are stored in the DB, then you need to create a simple servlet which just writes the
InputStream
of the image from the DB to theOutputStream
of the HTTP response. See also How to retrieve and display images from a database in a JSP page? (note that this doesn't require JSP/HTML, you can as good just use<h:graphicImage>
as it merely generates a HTML<img>
element).There's the PrimeFaces
<p:graphicImage>
, but this is a bit unintuitive to implement. See also Display dynamic image from database with p:graphicImage and StreamedContent.Update: since OmniFaces 2.0 (for JSF 2.2) there's a
<o:graphicImage>
component which supports among others directly referencing abyte[]
orInputStream
property in an@ApplicationScoped
managed bean in an intuitive way like below:In contrary to PrimeFaces
<p:graphicImage>
, no<f:param>
is needed and the EL method arguments are evaluated during render response phase, but the EL method itself is only invoked when the browser actually requests the image. See also the showcase and the blog on the subject.