Search code examples
xpagesssjs

beautify my URL from database.getfilepath


In my xpages app I want to redirect the user based upon a role. However the computed URL results in a ugly URL with %5C in the pathname

var baseURL = context.getUrl().toString().split(facesContext.getExternalContext().getRequest().getRequestURI())[0];

var path =escape(database.getFilePath());

if (context.getUser().getRoles().contains("[Administrator]") || context.getUser().getRoles().contains("[SuperAdmin]") || context.getUser().getRoles().contains("[Ledamot]")){
    facesContext.getExternalContext().redirect(baseURL + slash + path + "/employees.xsp?sorting=asc")
}else{
    context.redirectToPage("index.xsp")
}

This results in something like: : https://server/directory%5cdatabase.nsf/employees.xsp?sorting=asc


Solution

  • Since you are redirecting to the same database, you can calculate the url prefix (host + database path) like this:

    context.getUrl().toString().split(view.getPageName())[0]