In a PrimeFaces web application, I replaced the previous image loading strategy (which was temporarily saving the image files to the webapps/
directory of Tomcat and referencing them through <img src="...">
, which worked) by using <p:graphicImage>
. The very many images of the gallery are printed out in a loop with passing the ID. For a more or less big number of images, sometimes 90% of the images load, sometimes (especially if I set a break-point in the getter method returning the StreamedContent
object) just one. Which and how many images load is totally random.
Since various images do load (also in their correct position), I assume that my basic coding cannot be too wrong. Some debug output in that method showed me that the getter which returns the StreamedContent
is invoked in the second phase exactly for the images that are rendered. For the images that are not rendered, it is not invoked. In the network panel of Firefox, the corresponding HTTP requests were sent and return with 0 bytes:
I do not get any exception or stack trace anywhere, neither on the network console nor in my logs, though I set the root logger to debug. (I got a long log, but nothing that explains it to me.) Where or why are some HTTP requests not replied correctly?
This is the JSP code that generates the gallery:
<p:dataList styleClass="structureElementDataList"
id="structureElementDataList"
var="media"
value="#{stripe.medias}"
binding="#{structuredThumbnail}">
<p:panel id="structuredPagePanel">
<p:commandLink update="structureTreeForm, imagePreviewForm">
<div class="thumbnail-container">
<p:graphicImage value="#{DataEditorForm.galleryPanel.previewData}" class="thumbnail #{DataEditorForm.galleryPanel.selectedMedia eq media ? 'active' : ''}" rendered="#{media.showingInPreview}">
<f:param name="id" value="#{media.id}" />
</p:graphicImage>
<div class="thumbnail-overlay">
#{msgs.image} #{media.order}, #{msgs.page} #{media.orderlabel}
</div>
</div>
<f:setPropertyActionListener value="#{media}" target="#{DataEditorForm.galleryPanel.selectedMedia}"/>
<f:setPropertyActionListener value="#{stripe}" target="#{DataEditorForm.galleryPanel.selectedStripe}"/>
</p:commandLink>
</p:panel>
<p:draggable id="structuredPagesDraggable" for="imagePreviewForm:structuredPages:#{currentElement.rowIndex}:structureElementDataList:#{structuredThumbnail.rowIndex}:structuredPagePanel"
revert="true" stack=".ui-panel"/>
</p:dataList>
Here is the Java:
public StreamedContent getPreviewData() {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() != PhaseId.RENDER_RESPONSE) {
String id = context.getExternalContext().getRequestParameterMap().get("id");
GalleryMediaContent mediaContent = previewImageResolver.get(id);
if (Objects.nonNull(mediaContent)) {
return mediaContent.getPreviewData();
}
}
return new DefaultStreamedContent();
}
But, as I said, this code works part of the time, so I don’t really see what I am doing wrong. Has Tomcat, or JSF, a limitation on requests that I need to increase? Since I only get one image loaded if I set a break-point makes it look like a timing issue. (There is also not lots of threads stopping at that break point, which I would expect, but only one.)
Software versions:
Java 8.114
Tomcat: 8.0.52
MySQL: 5.7.19
ElasticSearch: 5.6.1
OmniFaces: 2.6.3
SpringFaces: 2.4.5.RELEASE
MyFaces: 2.2.12
PrimeFaces: 6.2
PrimeFaces Extensions: 6.1.1
Hibernate: 5.3.7.Final
Platform: Windows 10