primefaces / primefaces

Ultimate Component Suite for JavaServer Faces
http://www.primefaces.org
MIT License
1.79k stars 761 forks source link

FileDownload #9702

Closed morvael closed 1 year ago

morvael commented 1 year ago

Describe the bug

Migrated from PF 10 to PF 12 (Elite). All our ajax="false" p:fileDownloads stopped working and instead of desired file content return jsf page html. Can't switch to ajax downloads as they are all linked to view scoped beans. We often use a combination of actionListener in commandButton creating the streamed content which was then set as value for p:fileDownload.

I tried to make a reproducer, but it works properly in the test code (jetty + old Java EE 8). However similar code fails on Wildfly 27 with Jakarta EE 10. Anyway, I'm attaching it.

The "Download No AL" and "Ajax Download No AL" buttons can be used to test that the actionListener preparing file actually works - on fresh page load file is null, thus those buttons will trigger throwing AbortProcessingException. The "Download AL" is the one that should be working normally, downloading the file without using Ajax - this is the combination which stopped working for us and returns jsf page html. The "Ajax Download AL" will download error page as the contents of the file saying "Error in streaming dynamic resource. Verify you are not using a @ViewScoped bean.".

How can I get the ajax="false" download to work again in our setup as it worked before. The only thing that changed was PF version, Wildfly version and JavaEE to JakartaEE.

Reproducer

No response

Expected behavior

No response

PrimeFaces edition

Elite

PrimeFaces version

12.0.2

Theme

default

JSF implementation

Mojarra

JSF version

4.0

Java version

11.0.17+8

Browser(s)

Firefox 108.0.2

morvael commented 1 year ago

primefaces-test-download.zip

morvael commented 1 year ago

Tried ajax download in our setup and it returns empty file, logging the "correct" exception message complaining about view scoped. So that part doesn't work as advertised.

Not very eager to switch hundreds of p:fileDownload uses to ajax and download via REST/RequestScoped as this will be major rework. I'd rather be happy with getting ajax="false" downloads working again.

morvael commented 1 year ago

Hmm, testing in a special sandbox app on my local WildFly shows the same issue as in https://github.com/primefaces/primefaces/issues/6111 - server throws No enum constant com.sun.faces.context.ExternalContextImpl.PREDEFINED_COOKIE_PROPERTIES.SameSite

morvael commented 1 year ago
Caused by: java.lang.IllegalArgumentException: No enum constant com.sun.faces.context.ExternalContextImpl.PREDEFINED_COOKIE_PROPERTIES.SameSite
    at java.base/java.lang.Enum.valueOf(Enum.java:273)
    at com.sun.jsf-impl@4.0.0.SP01//com.sun.faces.context.ExternalContextImpl$PREDEFINED_COOKIE_PROPERTIES.valueOf(ExternalContextImpl.java:102)
    at com.sun.jsf-impl@4.0.0.SP01//com.sun.faces.context.ExternalContextImpl.addResponseCookie(ExternalContextImpl.java:765)
    at jakarta.faces.api//jakarta.faces.context.ExternalContextWrapper.addResponseCookie(ExternalContextWrapper.java:646)
    at deployment.sandbox-ear-1.ear.sandbox-web-1.war//org.primefaces.util.ResourceUtils.addResponseCookie(ResourceUtils.java:178)
    at deployment.sandbox-ear-1.ear.sandbox-web-1.war//org.primefaces.component.filedownload.FileDownloadActionListener.regularDownload(FileDownloadActionListener.java:93)
    at deployment.sandbox-ear-1.ear.sandbox-web-1.war//org.primefaces.component.filedownload.FileDownloadActionListener.processAction(FileDownloadActionListener.java:70)
morvael commented 1 year ago

Is this something to report to com.sun.jsf-impl authors?

tandraschko commented 1 year ago

this exception is not a PF problem and needs to be fixed in mojarra

melloware commented 1 year ago

Yep already reported and fixed: https://github.com/eclipse-ee4j/mojarra/issues/5165