Michael
Michael

Reputation: 51

Open NotesURL via redirect

I have a repeat-control which generates me a list of links to documents in a different database. Special on this task is that the XPage runs in the notes internal browther (NOT XPniC) and open the documents as real notes documents in the notes client (NOT Xpages). so far every thing works fine. Now I want too check if the document exists before I open the document.

My solution is an xAgent which check if the document exists and redirect to the NotesURL but I get the following error:

    Error source
    Page Name:/xaOpenDocument.xsp
    Exception
    Error while executing JavaScript action expression
    Script interpreter error, line=25, col=43: Error calling method 'redirect(java.lang.String)' on java class 'com.ibm.xsp.domino.context.DominoExternalContext'
    notes://SERVER01@SRV@DE@OU@MyCompany AG/__C1257B6B002A0472.nsf/0/C1257B6B002A0472C12574CD0024E6B9

The link to the xAgent looks like this:

http://SERVER02/dev/release_4/test_xui.nsf/xaOpenDocument.xsp?dbServer=SERVER01%2FSRV%2FDE%2FOU%2FMyCompany+AG&dbPath=dev%5C%5Crelease_4%5C%5Ctest_adr&docUNID=C1257B6B002A0472C12574CD0024E6B9

The xAgent code looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" rendered="false">
    <xp:this.afterPageLoad><![CDATA[#{javascript:var server:string = context.getUrlParameter("dbServer");
var db:string = context.getUrlParameter("dbPath");
var unid:string = context.getUrlParameter("docUNID");

var url:string = "";

var targetDB:NotesDatabase = session.getDatabase(server,db);

var doc:NotesDocument = targetDB.getDocumentByUNID(unid);

if(doc == null){
    requestScope.put("targetDocUNID",unid);
        println("xaOpendocument targetDocUNID: " + unid);
    requestScope.put("dbServer",server);
        println("xaOpendocument dbServer: " + server);
    requestScope.put("dbPath",db);
        println("xaOpendocument dbPath: " + db);
    requestScope.put("targetError","Dokument konnte nicht geöffnet werde. \n Document wurde verschoben oder entfernt.");
    println("xaOpendocument URL: xpErrorMessage.xsp");
    context.redirectToPage("xpErrorMessage.xsp");
}else{
    url = sessionUser.getDocumentURL(targetDB,unid);
    println("xaOpendocument: Dokument wurde gefunden... Umleiten!");
    println("xaOpendocument URL: " + url);
    facesContext.getExternalContext().redirect(url);
}}]]></xp:this.afterPageLoad>
</xp:view>

The Serverconsole shows me the following error lines:

30.07.2013 11:17:47   HTTP JVM: xaOpendocument: Dokument wurde gefunden... Umleiten!
30.07.2013 11:17:47   HTTP JVM: xaOpendocument URL: notes://SERVER02@SRV@DE@OU@MyCompany AG/__C1257B6B002A0472.nsf/0/C1257B6B002A0472C12574CD0024E6B9
30.07.2013 11:17:47   HTTP JVM: com.ibm.xsp.webapp.FacesServlet$ExtendedServletException: com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript action expression
30.07.2013 11:17:47   HTTP JVM: CLFAD0134E: Exception processing XPage request. For more detailed information, please consult error-log-0.xml located in F:/Lotus/data/domino/workspace/logs

I hope for some useful help - I wasted already to much time on this problem. I thought it should be simple. :/

Upvotes: 0

Views: 5401

Answers (3)

Michael
Michael

Reputation: 51

I figured it out.

The main problem was to call CSJS in backend functions for the redirect., becourse ssjs facesContext.GetExternalContext().redirect(url) could not handle my notes url (notes://...).

One hint by Frederic Norling was to use the view.postscript('window.location.href="+url+"'), but this function is only supported with Notes/Domino 8.5.3+ (sadly we use 8.5.2).

The enlightenment comes with my discovery of the EventHandler- Event "onComplet()". Now I create a Link component with a onClick()- Event:

    <xp:link escape="true" id="link1" tabindex="-1" style="font-weight:bold">
        <xp:this.text>MyLink</xp:this.text>
        <xp:eventHandler event="onclick" submit="true" 
            refreshMode="partial" refreshId="refreshCheckDoc">
            <xp:this.action>
                <![CDATA[#{javascript:<some code for checking my URL Target and write the URL in a requestScope variable when the target exist else I write a propper ErrorMessage in a requestScope Varaible>]]></xp:this.action>

On my XPage I have a panel with the id "refreshcheckDoc" an on this Panel I have two hidden fields.
The first Field get his value from the requestScope.url
the other get the requestScope.ErrorMessage.
On the onClick()- Event I attached the onComplet()- Event.
In the onComplet()- Event I check the content of the two fields.
Is the url empty AND the errorMessage I do nothing. If I have the url I call window.location.redirect(url),
if I have the ErrorMessage I use the alert() function to inform the user about the error.

Thanks for all Your help.
I hope this short description is helpful for others, too.

Upvotes: 0

Sven Hasselbach
Sven Hasselbach

Reputation: 10485

The problem is that the XPages Engine does not know the notes:// url format. Internally the given URL parameter will be converted with java.net.URL, and this throws an error.

Maybe you can send your own HTTP headers instead for the redirection to the notes:// URL.

EDIT:

This should do the trick:

}else{
   url = sessionUser.getDocumentURL(targetDB,unid);
   println("xaOpendocument: Dokument wurde gefunden... Umleiten!");
   println("xaOpendocument URL: " + url);
   var resp:com.ibm.xsp.webapp.XspHttpServletResponse = facesContext.getExternalContext().getResponse();
   resp.setStatus( 302 );
   resp.addHeader("Location", url );
   facesContext.responseComplete();
}

Upvotes: 1

Fredrik Norling
Fredrik Norling

Reputation: 3484

Your problem is that you are trying to do a server side redirect.

instead of facesContext.getExternalContext().redirect(url);

try this view.postscript('window.location.href="+url+"')

To make the redirect client side instead

Upvotes: 1

Related Questions