25 Sep URL:er till bilagor i XPages
Posted at 07:25h
in Uncategorized
I klassisk Domino-utveckling är URI till en bilaga:
http(s)://[server]/[application.nsf]/[viewname|0]/[UNID| ViewKey]/$File/[AttachmentName]?Open
Den syntaxen fungerar fortfarande bra på webben, men inte i XPages i Notes-klienten.
Den nya syntaxen för att skapa en URI till en bilaga är istället:
http(s)://[server]/[application.nsf]/xsp/.ibmmodres/domino/OpenAttachment/[application.nsf]/[UNID|/$File/[AttachmentName]?Open
Koden nedan (SSJS) är enklaste sättet att skapa URI till en bilaga.
function getAttachmentURL (docID:java.lang.String , attachmentName:java.lang.String) { var base = getBaseURL() ; var middle = "/xsp/.ibmmodres/domino/OpenAttachment" ; if (base.substr(0, 4) == "/xsp"){ middle += base.substr(4); } else { middle += base; } var result = base + middle +"/"+ docID +"/\$File/"+ attachmentName +"?Open"; return result; } function getBaseURL ( ) { var curURL = context.getUrl(); var curAdr = curURL.getAddress(); var rel = curURL. getSiteRelativeAddress(context); var step1 = curAdr.substr(0,curAdr.indexOf(rel)); // Now cut off the http var step2 = step1.substr(step1.indexOf("//")+ 2); var result = step2.substr(step2.indexOf("/")); return result; }
För att skapa en snygg länk i en ViewContainer kan nedan kodfragment användas.
<xp:viewPanel id="viewPanelReport" viewStyle="width:99%" var="viewEntry" rows="60"> <xp:this.facets> <xp:pager partialRefresh="true" layout="Previous Group Next" xp:key="headerPager" id="pager1"> </xp:pager> </xp:this.facets> <xp:this.data> <xp:dominoView var="myView" viewName="myv"></xp:dominoView> </xp:this.data> ... <xp:viewColumn id="viewColumn2" value=""> <xp:repeat var="attachment" rows="1"> <xp:this.value><![CDATA[#{javascript:try{ var rtItem:NotesRichTextItem = viewEntry.getDocument().getFirstItem("Body"); return rtItem.getEmbeddedObjects() } catch(e){ //Felhantering }}]]></xp:this.value> <xp:link id="link1" target="_blank"> <xp:this.value><![CDATA[#{javascript:var unid = viewEntry.getDocument().getUniversalID(); var attachmentName = attachment.getName(); var uri = getAttachmentURL(unid, attachmentName); return uri}]]></xp:this.value> <xp:this.text><![CDATA[#{javascript:"Öppna \""+ attachment.getName() +"\""}]]></xp:this.text> </xp:link> </xp:repeat> <xp:viewColumnHeader id="viewColumnHeader2"></xp:viewColumnHeader> </xp:viewColumn> ... </xp:viewPanel>