【发布时间】:2017-03-29 11:21:24
【问题描述】:
按照找到的解决方案,我已经实现了两个 StreamedContent bean 来动态加载图形图像 here
1) 第一个我在 contentFlow 中显示图像(一切正常)
<p:contentFlow value="#{imageBean.images}" var="image">
<p:graphicImage value="#{imageStreamer.fileContent}" styleClass="content" cache="false">
<f:param name="index" value="#{image.index}"/>
</p:graphicImage>
</p:contentFlow>
2) 对于第二个,我尝试使用 foreach(或重复)显示图像:
<c:forEach items="#{imageBean.images}" var="item" varStatus="varStatus">
<p:graphicImage value="#{imageStreamer.fileContent}" cache="false">
<f:param name="index" value="#{varStatus.index}" />
</p:graphicImage>
</c:forEach>
这不起作用。检查 (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) 始终为真。
如果我将 Bean 的范围更改为 RequestScoped,它就会起作用!我很困惑...有人可以帮助我吗?
托管 bean:
@ManagedBean
@ApplicationScoped
public class ImageStreamer{
public ImageStreamer(){}
public StreamedContent getFileContent(){
List<Link> links = this.getLinkItems();
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
FacesContext fc = FacesContext.getCurrentInstance();
String linkIndex = externalContext.getRequestParameterMap().get("index");
if(fc.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE){
return new DefaultStreamedContent();
}else{
int parsedIndex = Integer.parseInt(linkIndex);
Link ql = links.get(parsedIndex);
return new DefaultStreamedContent(new ByteArrayInputStream(ql.getBytes()), "image/png");
}
}
}
【问题讨论】:
-
您能提供您的托管 bean 代码吗?
-
我已将其添加到问题中
-
If I change the scope of the Bean to RequestScoped than it works。您的意思是在此处更改ImageStreamer的范围吗?这对您的应用程序来说根本不是问题。 -
对不起,我出了点问题...现在它正在工作...我真的不知道为什么...
标签: primefaces jsf-2 graphicimage