Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileDownload: request param not used in ajax requests #9675

Closed
NicolaIsotta opened this issue Jan 15, 2023 · 3 comments · Fixed by #9723
Closed

FileDownload: request param not used in ajax requests #9675

NicolaIsotta opened this issue Jan 15, 2023 · 3 comments · Fixed by #9723
Assignees
Labels
🐞 defect Bug...Something isn't working
Milestone

Comments

@NicolaIsotta
Copy link
Contributor

Describe the bug

f:param is ignored in p:fileDownload if it's an ajax request.
The bean is instantiated two times, the first time the param is present, but the StreamedContent used is the second one.

Reproducer

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>PrimeFaces Test</title>
    </h:head>
    <h:body>
        <h:form id="frmTest">
            <p:commandButton value="Ajax Download">
                <f:param name="param" value="PrimeFaces"/>
                <p:fileDownload value="#{requestBean.file}"/>
            </p:commandButton>
            <p:commandButton value="Normal Download" ajax="false">
                <f:param name="param" value="PrimeFaces"/>
                <p:fileDownload value="#{requestBean.file}"/>
            </p:commandButton>
        </h:form>
    </h:body>
</html>
package org.primefaces.test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;

import lombok.Getter;

import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;

@Named
@RequestScoped
public class RequestBean {

    @Getter
    private StreamedContent file;

    public RequestBean() {
        FacesContext fc = FacesContext.getCurrentInstance();
        String param = fc.getExternalContext().getRequestParameterMap().get("param");
        System.out.println(param);
        final String text = param == null ? "param not received" : "param received: " + param;
        file = DefaultStreamedContent.builder()
                .contentType("text/plain")
                .name("file.txt")
                .writer(t -> {
                    try {
                        t.write(text.getBytes(StandardCharsets.UTF_8));
                    } catch (IOException ex) {
                    }
                })
                .build();
    }
}

Expected behavior

The param should be used by ajax download too.
If it's not possible, it should be mentioned in the docs.

PrimeFaces edition

Community

PrimeFaces version

12.0.0

Theme

No response

JSF implementation

Mojarra

JSF version

2.3.18

Java version

jdk-11.0.13

Browser(s)

No response

@NicolaIsotta NicolaIsotta added ‼️ needs-triage Issue needs triaging 🐞 defect Bug...Something isn't working labels Jan 15, 2023
@melloware
Copy link
Member

@jepsar want to investigate this since you worked on the AJAX download stuff?

@jepsar
Copy link
Member

jepsar commented Jan 16, 2023

Sure, I can have a look.

@jepsar
Copy link
Member

jepsar commented Jan 24, 2023

Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 defect Bug...Something isn't working
Projects
None yet
3 participants