2

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.

Image of gallery with some images loading, others not

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:

enter image description here

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

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Matthias Ronge
  • 9,403
  • 7
  • 47
  • 63
  • How many images are there? I think there's a limit of 200 in the renderer. – Selaron Mar 05 '19 at 16:07
  • The conten type also differs (according to the browser...) html vs jpeg. Start with 4 images and increase to see if you reach a treshold where 1 stops working... Debug the browser network traffic etc... – Kukeltje Mar 05 '19 at 17:01
  • 2
    [This is the line where PF adds the hard coded limit of 200](https://github.com/primefaces/primefaces/blob/db1f4b76160799f2031f032ea101357e8775c2cf/src/main/java/org/primefaces/util/DynamicContentSrcBuilder.java#L75) dynamic resource entries. In case this is your problem, nothing prevents you from trying to `session.put(Constants.DYNAMIC_RESOURCES_MAPPING, new LimitedSizeHashMap(1024));` upon session creation. Not sure if it is a good idea to set it very high tbh. You'd better add pagination or infinit scroll to your gallery. – Selaron Mar 05 '19 at 18:07

0 Answers0