2

i am having p:filedownload in a primefaces data table like this

<p:column>
        <p:commandLink id="downloadLink"
                                style="color:blue;text-decoration:underline; "
                                disabled="#{ShipAttach.deleteSelect}" onclick="trailNewpage();"
                                value="#{ShipAttach.bpmfilename}" ajax="false">
                                <p:fileDownload contentDisposition="inline"
                                    value="#{filedownloadController.fileDownload(ShipAttach)}" />
                            </p:commandLink>
                        </p:column>

when i click on the link i am getting the file opened in a same window ,i was also able to open the file in the new tab by specifying the attribute target="_blank" i want these file to be opened in Childwindow,please help me thanks in advance.

Sai prateek
  • 11,842
  • 9
  • 51
  • 66
  • Try to first open a new window via a plain link. In there load a page where you do an automatic click on the download button. Al so simple... – Kukeltje Nov 26 '15 at 08:18
  • No actually the link is present in the data table ,For eg:if 10 rows are present ,if i want a file downloaded from first row i want to click in the first row and make the file content displayed in the child window –  Nov 26 '15 at 08:50
  • Same thing... Create a plain link that does a 'get request' (so not a commandLink) in a new window that contains parameters that point to the file to be downloaded... – Kukeltje Nov 26 '15 at 10:54
  • @Kukeltje When target="_blank" opening of new tab or childwindow is governed by browser settings or not? – Mahendran Ayyarsamy Kandiar Nov 26 '15 at 15:34
  • Yes, and I learned something tonight. According to the specs, `h:commandLink` supports target. Hmmmm http://stackoverflow.com/questions/14724518 `p:commandLink` does not – Kukeltje Nov 27 '15 at 01:42

1 Answers1

1

I had quite the same problem with a commandLink opening a fileDownload in a newTab. I was forced to use setTimeout to make it work (but I don't understand why).

With the old code, the link opens the new tab with the same page, but not the fileDownload :

<h:commandLink
        onclick="doStuff()"
        target="_blank">
    <p:fileDownload contentDisposition="inline" value="#{myFile}"/>
</h:commandLink>

With the new code, the link opens the new tab with the fileDownload :

<h:commandLink
        onclick="setTimeout(doStuff, 0)"
        target="_blank">
    <p:fileDownload contentDisposition="inline" value="#{myFile}"/>
</h:commandLink>
Bludwarf
  • 824
  • 9
  • 21
  • What does your 'doStuff' do? What if you remove it? Does it work then? – Kukeltje Jul 31 '19 at 14:54
  • 1
    Oh and this question is about the **PrimeFaces** `p:commandLink`, not the `h:commandLink`... So you answer won't help here. Maybe if you create a new question with your original code (in [mcve] flavour) we can see what was/is your problem and why your change worked for you – Kukeltje Jul 31 '19 at 15:01