This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



May 3, 2011, 4:11 PM
47 Posts

xp:link and computed server-relative URL?

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.2
  • Role: Developer
  • Tags:
  • Replies: 4
 Hi all,
 
I hope I am just missing something. I have an xp:link control for which I am trying to compute a server-relative URL (one that starts with a '/') which points to another database. If I enter it as a static value (i.e. 
 
<xp:link escape="true" text="Link" id="link1" value="/path/to/target/database.nsf"></xp:link>
 
), it works correctly, but if I compute the same string using javascript (i.e.
 
<xp:link escape="true" text="Link" id="link1"> <xp:this.value> <![CDATA[#{javascript:"/path/to/target/database.nsf"}]]>  </xp:this.value></xp:link>
 
), in the HTML generated, the href attribute has the path to the current database prepended, something like this:
 
<a id="view:_id1:link1" href="/path/to/current/database.nsf/path/to/target/database.nsf" class="xspLink"> 
 
Am I missing an attribute or a secret way to format the computed value so that it will not prepend the current database path? 
 
Thanks, 
 
Rich 
May 4, 2011, 7:55 AM
7 Posts
Re: xp:link and computed server-relative URL?
 
Are you sure <xp:link escape="true" text="Link" id="link1" value="/path/to/target/database.nsf"></xp:link> generates a correct url? Because I tested this on my machine, and I get an incorrect url (also with the current db still in the url)
 
I think if you specify an relative url, xpages will automatically assumes it points to the database you are in. Use full urls if you want to link to another db.


May 4, 2011, 8:31 PM
47 Posts
Re: xp:link and computed server-relative URL?
sometimes I think I'm going mad, other times I know it is true...
 
you are correct, even the statically entered URL has the local db name prepended. 
 
I really do need server-relative URLs as the Domino server is accessed via a reverse proxy, and trying to build a URL including protocol, server name and port via calls like context.getURL () only know the directly accessed value on the server.
 
I suppose I can forgo using xp:link and build my own using computed text. Just more work.
 
Rich 
 
May 5, 2011, 7:30 AM
261 Posts
Re: xp:link and computed server-relative URL?
Pretty strange this doesn't work out of the box.
 
As a (kinda strange) workaround you could use the ../ syntax. Depending on the location (folder depth) of you source database you have to prepend a number of occurrences of that string. To calculate how many, you could use something like this:
 
var linkToServerRoot = @Repeat("../",  database.getFilePath().split(java.io.File.separator).length);
var targetDb = "app/dbs-admin.nsf";

linkToServerRoot  + targetDb;
 
Mark
May 6, 2011, 3:53 PM
47 Posts
Re: xp:link and computed server-relative URL?
 Thanks Mark, that's an interesting approach. I had half a passing thought to try something like that but I just plowed ahead and generated my HTML in a computed field. If I have to revisit this, I may switch to your solution as it means that items inside the link tag won't need to be hard coded.
 
Rich 
 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal