Search code examples
filexpageslotus-domino

XPages: File Download control link url


I have a file download control that lists attachments from some documents in my database. I want to display an icon next to each row and make it a link to the attachment of the row.

If not sure how to do it for each row, let's assume that i have only 1 row. How can i get the link of the attachment so as to declare it as href in a link control?


Solution

  • As i already mentioned in my Comment if you are using a <xp:fileDownload> you can add a Icon if you set displayType="true" and because you didnt add code to your question i guess your code could look something like this:

    //..your code
                    <xp:panel id="row">
                        <xp:this.data>
                            <xp:dominoDocument
                                var="document1"
                                action="openDocument"
                                documentId="#{javascript://example... viewEntry.getDocument().getUniversalId()}">
                            </xp:dominoDocument>
                        </xp:this.data>
                        <xp:fileDownload
                            rows="30"
                            id="fileDownload1"
                            displayLastModified="false"
                            value="#{document1.Body}"
                            displayType="true">
                        </xp:fileDownload>
                    </xp:panel>
    //..your code
    

    or if you dont use a <xp:fileDownload> and maby just Display rows with the attachment Name you could use something like this:

    //... your code
                <xp:panel id="row">
                <xp:repeat
                    id="repeat1"
                    rows="30"
                    value="#{javascript:@AttachmentNames()}"
                    indexVar="attachmentIndex"
                    var="attachment">
                    <xp:link
                        escape="true"
                        text="#{javascript:attachment;}"
                        id="link1"
                        target="_blank">
                        <xp:this.value><![CDATA[#{javascript:
                            var url = facesContext.getExternalContext().getRequest().getContextPath() + "/0/" +  
                /*in my case: viewEntry.getDocument().getUniversalID()*/ 
                + "/$File/"+ AttachmentName;        
                            return url;}]]></xp:this.value>
                        <xp:image id="image1">
                            <xp:this.url><![CDATA[#{javascript://
                                var pdfImage = 'pdf.gif';
                                if(attachment.indexOf("pdf")> 0)
                                    return pdfImage;
                                }]]></xp:this.url>
                        </xp:image>&#160;
                    </xp:link>
                    <br></br>
                </xp:repeat>
            </xp:panel>//...your code
    

    The <xp:repeat> inside your row will create a link for each attachment inside of your document you can remove it if you only have one attachment per document.