我正在尝试显示带有动态内容的 p:graphicImage。我的观点:

<p:graphicImage value="#{loginBean.loginImage}" /> 

支持 bean(Spring Bean/Singleton Scope)

public StreamedContent getLoginImage() throws IOException 
    { 
        if (FacesContext.getCurrentInstance().getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) 
        { 
            return new DefaultStreamedContent(); 
        } 
 
        String loginImage; 
 
        if (developmentState) 
        { 
            loginImage = "dev.jpg"; 
 
        } else 
        { 
            loginImage = "prod.jpg"; 
        } 
 
        final byte[] bytes = ... load bytes 
        return new DefaultStreamedContent(new ByteArrayInputStream(bytes), "image/jpg"); 
    } 

这在 Firefox/Chrome 中运行良好。 但它在 IE 10+ 中失败呈现的不是真实图像而是空框

我的登录页面使用:

<h:head> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
 
    <f:facet name="first"> 
        <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
    </f:facet> 
</h:head> 

页面已呈现。 IE 中仅缺少图像(Firefox/Chrome 正确呈现)。即使启用了 TRACE 级别,服务器端也没有错误。

即:

<img id="j_idt10" alt="" src="/appContext/javax.faces.resource/dynamiccontent.properties.xhtml?ln=primefaces&amp;pfdrid=ufpDFHhNpCx9dNk92OfD7uAPP6LjduXzuDwZf73cSco%3D&amp;pfdrt=sc&amp;pfdrid_c=true"> 

Chrome :

<img id="j_idt10" src="/appContext/javax.faces.resource/dynamiccontent.properties.xhtml?ln=primefaces&amp;pfdrid=ufpDFHhNpCx9dNk92OfD7uAPP6LjduXzuDwZf73cSco%3D&amp;pfdrt=sc&amp;pfdrid_c=true" alt=""> 

火狐:

<img alt="" src="/appContext/javax.faces.resource/dynamiccontent.properties.xhtml?ln=primefaces&amp;pfdrid=ufpDFHhNpCx9dNk92OfD7uAPP6LjduXzuDwZf73cSco%3D&amp;pfdrt=sc&amp;pfdrid_c=true" id="j_idt10"> 

IExplore DEV 控制台说:

HTTP    GET 200 44,29 KB    16 ms   <img> for image 
/appConctext/javax.faces.resource/dynamiccontent.properties.xhtml?ln=primefaces&pfdrid=ufpDFHhNpCx9dNk92OfD7uAPP6LjduXzuDwZf73cSco%3D&pfdrt=sc&pfdrid_c=true 

任何帮助将不胜感激。谢谢

请您参考如下方法:

受 BalusC 评论的启发,我在 DefaultStreamedContent 部分添加了 Content-Type header "image/jpeg"

return new DefaultStreamedContent(new ByteArrayInputStream(bytes), "image/jpg"); 

注意:“image/jpg”不适用于 Internet Explorer


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!