Redirect to another database on the server

function redirectToOtherDb(targetDb,pageName,docId,action,moreParams) {
/* 
Opens another database on the same server
Only the targetDb parameter is required
If the XPage name is null but the document UNID is given, then it assumes the document form is associated with an XPage.

@param targetDb: Path and database name under data directory without an initial slash, e.g., "intranet/myapp.nsf" 
@param pageName: Name of XPage without the extension, .e.g., "home"
@param docId: The specfic document UNID
@param action: One of the common document actions, e.g., "edit" or "read"
@param moreParams: Additional parameters in the query string, e.g. "&thisvalue=abc&thatvalue=xyz"
	If there are no other parameters, you do not need the initial ampersand as in the example.
@return: Requested database in same browser window 
*/ 

var url:XSPUrl = new XSPUrl(database.getHttpURL()); 
var host:String = url.getHost();
var protocol:String = url.getScheme();
var baseURL:String = protocol + "://" + host + "/" + targetDb;
if (targetDb == null) {
	facesContext.getExternalContext().redirect(url.toString());
 } else {
	if (pageName == null && docId == null) {
		facesContext.getExternalContext().redirect(baseURL);
	} else {
		var pn = (pageName == null || pageName == "") ? "/$$OpenDominoDocument.xsp" : "/" + pageName + ".xsp";
		var id = (docId == null || docId == "") ? "" : "documentId=" + docId;
		var a = (action == null || action == "") ? "" : "&action=" + action + "Document";
		var mp = (moreParams == null || moreParams == "") ? "" : moreParams;
		var q = ( (id + a + mp) == "" ) ? "" : "?";
		facesContext.getExternalContext().redirect(baseURL + pn + q + id + a + mp);
	}
 }
}




JavaScript (Server)
Michael McGarel
August 14, 2012 2:32 PM
Rating
311

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...