通过重定向打开NotesURL

时间:2013-07-30 10:19:36

标签: xpages lotus-notes xpages-ssjs

我有一个重复控件,它生成一个指向不同数据库中文档的链接列表。 这项任务的特殊之处在于XPage在内部注释(不是XPniC)中运行,并在注释客户端(非Xpages)中将文档作为真实注释文档打开。到目前为止,每件事都很好。 现在我想在打开文档之前检查文档是否存在。

我的解决方案是一个xAgent,它检查文档是否存在并重定向到NotesURL但是我收到以下错误:

    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

xAgent的链接如下所示:

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

xAgent代码如下所示:

<?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>

Serverconsole向我显示以下错误行:

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

我希望得到一些有用的帮助 - 我已经浪费了很多时间来解决这个问题。我认为应该很简单。 :/

3 个答案:

答案 0 :(得分:1)

问题是XPages Engine不知道 notes:// url格式。在内部,给定的URL参数将使用 java.net.URL 进行转换,这会引发错误。

也许您可以发送自己的HTTP标头,而不是重定向到 notes:// 网址。

修改

这应该可以解决问题:

}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();
}

答案 1 :(得分:1)

您的问题是您正在尝试进行服务器端重定向。

而不是 facesContext.getExternalContext()重定向(URL);

试试这个 view.postscript( 'window.location.href = “+ URL +”')

改为使用重定向客户端

答案 2 :(得分:0)

我明白了。

主要问题是在重定向的后端函数中调用CSJS。,因为ssjs facesContext.GetExternalContext().redirect(url)无法处理我的笔记url(注释:// ...)。

Frederic Norling的一个提示是使用view.postscript('window.location.href="+url+"'),但只有Notes / Domino 8.5.3+支持此功能(遗憾的是我们使用8.5.2)。

启蒙来自我发现的EventHandler-事件“onComplet()”。 现在我创建一个带有onClick()的链接组件 - 事件:

    <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>

在我的XPage上我有一个id为“refreshcheckDoc”的面板,在这个面板上我有两个隐藏的字段。
第一个字段从requestScope.url获取他的值,另一个得到requestScope .ErrorMessage。
在onClick() - 事件中我附加了onComplet() - Event。
在onComplet() - 事件中,我检查两个字段的内容。
网址是空的还是errorMessage我什么都不做。如果我有网址,我会调用window.location.redirect(url),如果我有ErrorMessage,我会使用alert()函数通知用户错误。

感谢您的帮助。我希望这个简短的描述对其他人也有帮助。