XPages: How do I get the page url after a page loads?

I’m trying to create a “breadcrumb navigator” for my app, similar to the one shown in Help.

Something like this:

Home > First Page > Second Page > Curr Page

so the user can simply see how they got to where they are and then can also quickly jump back to any previous page by clicking on the appropriate link.

I have the page names working for my link labels, but I can’t get the url values for the onclick events.

I’m trying to get the page url using:

context.getUrl().toString();

But, I’ve tried putting it in the form custom control beforePageLoad, afterPageLoad, postOpenDocument - they all return an empty string.

If I simply put the code in a computedfield, it shows the url correctly, so I suspect that I’m trying to get it when the page doesn’t quite know it yet. I also tried putting the code in the afterPageLoad of the xpage itself (which contains the form custom control), but still get an empty string.

Is there another command I should be using to get this? - and where do I put it?

Background: I created a function in my xpServerSide script library to process the navigators values, and then in each page, I’m just calling UpdateNavigator(pgname, pglink). So, as each page is opened, I call the function to update the navigator.

Can I accomplish what I’m after this way? - or, should I be using another method?

Another thought - is there a size limit to a sessionScope variable? Maybe the sessionScope var can’t hold that long of a string?

tia

Subject: Have you tried afterRenderResponse?

If this doesn’t work, let me know and we’ll look into a few other approaches.

-Chris

Subject: That’s it! Thank you!

Subject: well, I thought I had it - but, noooooo

I’m not sure what I was looking at when I posted last time, but I can’t get it to work now.

My approach is this: when a page is opened, I pass in the page name and url to a script library function that will either add the entries to a sessionScope var - or, reset the sessionScope var to all pages up to the current page (when returning to a page).

Here’s what I have in the afterRenderResponse event of my custom control (which is my form):

//update the navigator

var pgname = "Task # " + String(dominoDocument1.getItemValueInteger(“ID”));

var pglink = context.getUrl().toString();

UpdateNavigator(pgname, pglink)

This is my script library function:

function UpdateNavigator(pgname:string, pglink:string){

//values are concatenated with ~

var namestr = sessionScope.get("NavNames");

var linkstr = sessionScope.get("NavLinks");

if (namestr==null){

	var namearr = new Array();

	var tmp = namearr.push(pgname);

	var linkarr = new Array();

	var tmp = linkarr.push(pglink);

}	

else {

	if (namestr.indexOf("~")==-1){

		var namearr = new Array(namestr);

		var linkarr = new Array(linkstr);

	}

	else {

		var namearr = namestr.split("~");

		var linkarr = linkstr.split("~");

	}

	//check if returning to this page

	var found = false;

	for (var i = 0; i < namearr.length; i++) {

		if (namearr[i]==pgname){

			namearr = namearr.slice(0,i+1);

			linkarr = linkarr.slice(0,i+1);

			var found = true;

		}

	}

	if (found==false) {

		tmp = namearr.push(pgname);

		tmp = linkarr.push(pglink);

	}

}

if (namearr.length==1){

	sessionScope.put("NavNames", namearr[0]);

	sessionScope.put("NavLinks", linkarr[0]);

}

else {

	sessionScope.put("NavNames", namearr.join("~"));

	sessionScope.put("NavLinks", linkarr.join("~"));

}

}

My links on my navigator custom control each have a formula to calculate the page name for the label and the url for the onclick event. Here’s the onclick event code for the first link:

var arrstr = sessionScope.get(“NavLinks”);

if (arrstr==null){

return("");

}

else {

if (arrstr.indexOf("~")==-1){

	var arr = new Array(arrstr);

}

else {

	var arr = arrstr.split("~");

}

}

if (arr.length>0){

addr = arr[0];

}

facesContext.getExternalContext().redirect(addr)

I put a computed field on my page to show me the NavLinks and NavNames values so I can see that they are being populated correctly. With the code in the afterRenderResponse event, neither value is updated (maybe because its after the page is rendered?) If I put the code in the afterPageLoad event, the NavNames will update correctly, but not the NavLinks.

I must be missing something in the timing of when the page updates and when the vars are updated.

Any other ideas?

Subject: use beforeRenderResponse to access URL

In my tests, I found that context.getUrl() is only valid in the beforeRenderResponse event.

Here’s a simple xpage that illustrates:

<?xml version="1.0" encoding="UTF-8"?>

<xp:view xmlns:xp=“http://www.ibm.com/xsp/core”>

<xp:this.beforeRenderResponse><![CDATA[#{javascript:viewScope.url = context.getUrl().toString()}]]></xp:this.beforeRenderResponse>

<xp:text escape="true" id="computedField1" value="#{javascript:'page:' + context.getUrl()}"></xp:text>

<xp:br></xp:br>

<xp:text escape="true" id="computedField2" value="#{javascript:'event:' + viewScope.url}"></xp:text>

</xp:view>

If you change the event to anything other than beforeRenderResponse, the url is null.