【发布时间】:2013-09-29 13:56:55
【问题描述】:
我已经成功实现了 BalusC 建议的解决方案,用于在数据表中呈现动态图像(代码在此处进一步发布)。我面临的问题是:
问题
我在数据表中使用 pagination,当我移动到我从未访问过的页面时,图像呈现良好。但是当我返回之前访问过的页面时,即使返回了该图像的 StreamedContent,图像也不会显示。
代码
// ImageBean - SessionScoped
// Get image for compound
public StreamedContent scaledImageById() {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
return new DefaultStreamedContent();
} else {
String idStr = context.getExternalContext().
getRequestParameterMap().get("id");
StreamedContent image = scaledCompoundImageMap.
get(Integer.valueOf(idStr));
return image;
}
}
// Controller - ViewScoped
<p:dataTable id="cTable" value="#{controller.compoundList}" var="compound">
<p:column headerText="Structure" style="text-align:center">
<p:graphicImage id="scaledImage"
value="#{imageBean.scaledImageById()}"
cache="false">
<f:param name="id" value="#{compound.id}" />
</p:graphicImage>
</p:column>
...
因此,当我在分页器中访问新页面时,图像显示正常。但是当我回到一个已经访问过的页面时,图像没有显示(即使 scaledImageById 被调用了两次并且 StreamedContent 被很好地返回)。
如果您需要任何其他代码,请告诉我,我们将不胜感激。谢谢。
阿卜杜勒
【问题讨论】:
-
浏览器产生了哪些请求?您应该在网络选项卡中的 firebug 下跟踪您的问题。
-
谢谢卢卡斯。是的,我检查了网络选项卡,我看到 Primefaces 为每个图像生成一个动态 url。像这样的东西:'dynamiccontent.properties.jsf?ln=primefaces&pfdrid=xxxxx&id=13。当我第一次访问分页器时单击它,它可以很好地打开图像,但是当我重新访问页面并打开这样的链接时,没有图像。不知道为什么我下次访问同一页面时该动态链接不起作用。
标签: jsf primefaces datatable pagination dynamic-image-generation