Home.xhtml
Code: Select all
<div class="dataTable">
<h:form id="imageList">
<p:dataTable var="img" value="#{imageView.images}" rowKey="#{img.id}" rows="10" lazy="true" paginator="true">
<p:column width="50" headerText="Id">
<h:outputText value="#{img.id}"/>
</p:column>
<p:column headerText="Image">
<p:graphicImage style="width:80px; height:80px" value="#{imageView.tempImg}">
<f:param name="something" value="#{img.id}" />
</p:graphicImage>
</p:column>
<p:column width="200" headerText="Name">
<h:outputText value="#{img.name}"/>
</p:column>
<p:column width="200" headerText="Edit">
<h:commandButton value="Enter" action="Image?faces-redirect=true" />
</p:column>
</p:dataTable>
</h:form>
</div>
Code: Select all
<h:form onsubmit="#{getComponents.getAllComponents()}" id="home">
<div>
<p:graphicImage id="tempImg" value="#{imageView.tempImg}" />
</div>
</h:form>
Code: Select all
public StreamedContent getTempImg() 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 image. Return a real StreamedContent with the image bytes.
String imgId = context.getExternalContext().getRequestParameterMap().get("something");
System.out.println(imgId);
System.out.println("done");
Image image = ((ImageLazyLoad) images).getRowData(imgId);
tempImg= new DefaultStreamedContent(new ByteArrayInputStream(image.getByteData()));
return this.tempImg;
}
}