p:filedownload from p:datatable with ViewScoped managed bean

UI Components for JSF
Post Reply
d1van
Posts: 7
Joined: 29 Jun 2011, 22:56

28 Aug 2011, 17:03

p:filedownload from p:datatable with ViewScoped managed bean wont work. It calls the methods prepareFile and getFile twice. In first call of the methods I mentioned it sets the first file from the table, and in the second call of the methods it sets the right file, but it always downloads only the first one and the second one is never downloaded.

Why does it call twice? Why does it set the first file from the table? Any ideas?

Here's my code:

Code: Select all

<p:dataTable id="offer_attachment_datatable"
                     widgetVar="offer_attachment_datatable"
                     var="attachment"
                     value="#{offerBean.offerAttachments}">
            <p:column>
                <f:facet name="header"/>
                <p:commandLink ajax="false" actionListener="#{offerBean.prepareFile(attachment)}" title="#{attachment.name}">
                    <p:graphicImage value="/resources/themes/navigator_b2e/images/drive-download.png" />
                    <p:fileDownload value="#{offerBean.file}"/>
                </p:commandLink>
            </p:column>
</p:dataTable>
and in managed bean (simplified):

Code: Select all

    private StreamedContent file;
    private InputStream stream;

    public void prepareFile(OfferAttachment attachment){
        System.out.println("Attachment: "+attachment.getName());
        stream = new ByteArrayInputStream(attachment.getAttachment());
        file = new DefaultStreamedContent(stream, "text/plain", attachment.getName());
        stream = null;
    }

    public StreamedContent getFile() {
        System.out.println("File: "+file.getName());
        return file;
    }

    public void setFile(StreamedContent file) {
        this.file = file;
    }
Glassfish 3.1, Primefaces 2.2.1.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

28 Aug 2011, 17:09

Use f:param when using fileDownload inside data iteration components to identify which file to download.

d1van
Posts: 7
Joined: 29 Jun 2011, 22:56

28 Aug 2011, 17:49

I've passed a rowIndex as f:param, but it always passes the same rowIndex :cry:
Glassfish 3.1, Primefaces 2.2.1.

d1van
Posts: 7
Joined: 29 Jun 2011, 22:56

28 Aug 2011, 17:50

also, I'm using PF 2.2.1 if that matters
Glassfish 3.1, Primefaces 2.2.1.

d1van
Posts: 7
Joined: 29 Jun 2011, 22:56

29 Aug 2011, 09:25

I think this ajax=false in filedownload blocks it somehow... any ideas?
Glassfish 3.1, Primefaces 2.2.1.

d1van
Posts: 7
Joined: 29 Jun 2011, 22:56

29 Aug 2011, 11:31

Ok, guys, so I made a workaround with a simple p:confirmDialog where I extracted the problematic ajax=false command link, so I select the attachment by clicking it in p:datatable and execute the download from the p:confirmdialog.
Glassfish 3.1, Primefaces 2.2.1.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

29 Aug 2011, 11:35

Not rowIndex, better sth from your domain model to identify the data to export.

d1van
Posts: 7
Joined: 29 Jun 2011, 22:56

29 Aug 2011, 11:42

I tried that too, always sends the first selected information... very strange.

But thank you!
Glassfish 3.1, Primefaces 2.2.1.

d1van
Posts: 7
Joined: 29 Jun 2011, 22:56

30 Aug 2011, 10:45

Now it seems like the bean is destroyed. It downloads the right file, but when I try some action after that, i get

Code: Select all

SEVERE: com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean offerBean
Glassfish 3.1, Primefaces 2.2.1.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 50 guests