I´m trying to show one image that can be stored in memory on in one folder, firts I´m trying to show the content on the folder...
I´m calling a dialog
with a commandbutton
and inside in the dialog
there is a graphicImage
But it didn´t show the image.
So whats wrong?
<p:dialog header="#{lbl['LABEL.ATENDENTE.IMAGEMCERTIFICADO']}" widgetVar="dlgViewCpfImagem" modal="true" resizable="false" closable="false" dynamic="true">
<h:form id="formDlgViewCpfImagem" enctype="multipart/form-data">
<p:messages id="messageDlgViewCpfImagem" showDetail="true"/>
<p:panelGrid styleClass="noBorders panelGridCenter gridNoBackground">
<p:row>
<p:column>
<p:graphicImage value="#{atendenteBean.fileCpf.getAbsolutePath()}"/>
</p:column>
</p:row>
</p:panelGrid>
</h:form>
<center>
<p:commandButton process="@this" value="#{lbl['BOTAO.FECHAR']}" oncomplete="dlgViewCpfImagem.hide()" update=":form:panelAnexarArquivo"/>
</center>
</p:dialog>
<p:column rendered="#{not empty atendenteBean.pojo.imgCpf}">
<p:commandButton process="@this" icon="botaoLog" styleClass="botaoImagem" oncomplete="dlgViewCpfImagem.show()"/>
</p:column>
It appears that you are trying to show a file point to where it is stored in your file system. That won't work unless you use Dynamic Image Streaming . See the example below:
Managed Bean
import java.io.File;
import java.io.InputStream;
import javax.faces.bean.SessionScoped;
import org.apache.commons.io.FileUtils;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
@ManagedBean
@SessionScoped
public class DynamicImageController {
private StreamedContent graphicImage;
public DynamicImageController() {
try {
//The image file you want to show
File file = new File("d:\\image.png");
InputStream is = FileUtils.openInputStream(file);
graphicImage = new DefaultStreamedContent(is, "image/png");
} catch (Exception e) {
e.printStackTrace();
}
}
public StreamedContent getGraphicImage() {
return graphicImage;
}
}
PS: I use a session scoped bean because I want it to be simple. You should think about a more sophisticate mechanism to avoid storing too much data in session. Remember that the image tag uses a different http connection and ViewScoped beans might not be a good choice for this.
The View
<p:graphicImage value="#{dynamicImageController.graphicImage}" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.