从数据库显示图像,图像属性是好的,但显示其他图像。使用Primefaces

时间:2013-11-18 16:37:53

标签: jsf-2 primefaces

我尝试在数据表中为每个人显示db中的一些imagen,但数据表显示错误的图像。我不知道应用程序在哪里提供imagen,因为在支持bean中显示beacause,imagen是其他的。

<p:column>
   <p:graphicImage id="img2" value="#{listadoPersonasMB.fotoPersona}">
         <f:param name="id2" value="#{item.idPersona}" />
   </p:graphicImage>
 </p:column>

支持豆

  FacesContext context = FacesContext.getCurrentInstance();
        if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
            return new DefaultStreamedContent();
        } else {
            String studentId = context.getExternalContext().getRequestParameterMap().get("id2");
            FacesContext ctx = FacesContext.getCurrentInstance();
            ValueExpression vex = ctx.getApplication().getExpressionFactory().createValueExpression(ctx.getELContext(), "#{controladorMB}", ControladorMB.class);
            ControladorMB gMB = (ControladorMB) vex.getValue(ctx.getELContext());
            return new DefaultStreamedContent(new ByteArrayInputStream(gMB.getPersonaBean().devuelveFotoPersona(Integer.parseInt(studentId))));}

1 个答案:

答案 0 :(得分:0)

浏览器在缓存上保留一些图像我试试这个并正常工作:

1-设置禁用缓存。把它放在facesconfig.xml

  <lifecycle>
    <phase-listener id="nocache">jsfUtil.CacheControlPhaseListener</phase-listener>
</lifecycle>

2-班级代码:

public class CacheControlPhaseListener implements PhaseListener {

@Override
public PhaseId getPhaseId() {
    return PhaseId.RENDER_RESPONSE;
}

@Override
public void afterPhase(PhaseEvent event) {
}

@Override
    public void beforePhase(PhaseEvent event) {
    FacesContext facesContext = event.getFacesContext();
    HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    response.setDateHeader("Expires", 0); // Proxies.
}

3- reaload page

 <p:dialog width="800" onHide="window.location.reload()" height="600"  appendTo="@(body)" modal="true" widgetVar="dialogModi" header="Editar persona" id="atDlg">