PrimeFaces 6.0 does not cache images on the client side

UI Components for JSF
Post Reply
Tiny
Posts: 79
Joined: 03 Jul 2013, 17:40

22 Jul 2016, 16:41

Given a <p:dataTable> rendering images in one of the columns.

Code: Select all

<p:dataTable id="dataTable" var="row" value="#{bean}"
             lazy="true"
             skipChildren="true">

    <p:column headerText="Image">
        <p:cellEditor>
            <f:facet name="output">
                <p:graphicImage value="#{imageBean.image}" stream="true" cache="true">
                    <f:param name="id" value="#{row.id}"/>
                    <f:param name="width" value="100"/>
                    <f:param name="height" value="100"/>
                </p:graphicImage>
            </f:facet>

            <f:facet name="input">
                <p:graphicImage value="#{imageBean.image}" stream="true" cache="true">
                    <f:param name="id" value="#{row.id}"/>
                    <f:param name="width" value="100"/>
                    <f:param name="height" value="100"/>
                </p:graphicImage>

                <!-- <p:overlayPanel> here for file upload -->
            </f:facet>
        </p:cellEditor>
    </p:column>

    <p:column headerText="Edit">
        <p:rowEditor/>
    </p:column>
</p:dataTable>
The data table may contain other essential commonly used attributes and columns as and when needed.

When this table is (Ajaxically) updated, all images are fetched from the database (or disk file system, if used) as if they are not cached by the browser at all even though cache is explicitly set to true (which is the default value). This was working well previoulsly with PrimeFaces 5.3 final.

The migration guide states nothing about it but apparently something has been changed about caching <p:graphicImage>.

https://github.com/primefaces/primeface ... tion-Guide

Any suggestion to fix the problem?

In the example above, if the table contains 5 images in 5 rows, for example, the database will be queried 10 times on every single update made to the <p:dataTable> (except inline row editing which defaults to the current row) which should not happen as getting images especially from a database is very costly.
PF 6.0, PF Ext 6.0.0, Mojarra 2.2.13, OmniFaces 2.5
Java EE 7, JAAS, EJB 3.2
Spring 4.0 GA, Spring Security 3.2.0 GA, Struts 2.3.16
EclipseLink 2.6.3 (JPA 2.1), Hibernate 5.2.1 (JPA 2.1)
GlassFish 4.1, WildFly 10.0.0, Tomcat 8.0.29
NetBeans 8.1, JDK 8u66

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

26 Jul 2016, 20:42

Tiny wrote:In the example above, if the table contains 5 images in 5 rows, for example, the database will be queried 10 times on every single update made to the <p:dataTable> (except inline row editing which defaults to the current row) which should not happen as getting images especially from a database is very costly.
Why JSF calls getters multiple times (see BalusC's answer)

Also, maybe you need to consider writing a Servlet filter for browser caching (see this too)
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

27 Jul 2016, 00:01

@Howard: did you read it worked with 5.3? And Tiny knows the 'getter being called multiple times' Tiny is avtively answering on Stackoverflow to

Tiny
Posts: 79
Joined: 03 Jul 2013, 17:40

18 Sep 2016, 07:09

This is an issue in PrimeFaces 6.0 and has been reported on the issue tracker.

https://github.com/primefaces/primefaces/issues/1765
PF 6.0, PF Ext 6.0.0, Mojarra 2.2.13, OmniFaces 2.5
Java EE 7, JAAS, EJB 3.2
Spring 4.0 GA, Spring Security 3.2.0 GA, Struts 2.3.16
EclipseLink 2.6.3 (JPA 2.1), Hibernate 5.2.1 (JPA 2.1)
GlassFish 4.1, WildFly 10.0.0, Tomcat 8.0.29
NetBeans 8.1, JDK 8u66

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 33 guests