xpages:什么可以在保存页面时停止代码停止?

时间:2015-10-20 18:17:20

标签: xpages xpages-ssjs

最后更新:问题的来源

我有一个页面,基于一个表单,该表单已从应用程序的前一个版本中删除了大多数计算字段(因此文档实际上可以传递computewithform函数),并且在保存文档时出现问题。我有在Notes客户端(以前的应用程序版本)中创建的文档,这些文档已转换为mime,并且在新的xpages应用程序中使用CKEditor创建的一些文档保存在标记为存储为的富文本字段中MIME也是。

我有一个“发布”文档的按钮。该代码适用于在新应用程序中创建的文档,但它似乎停止在以前的应用程序版本中创建的文档的某处。

就http流量来说,这就是IE陷阱:

A case that works:
/mydb.nsf/page.xsp?action=editDocument&documentId=353B2 HTTP    POST    302     244 B   218 ms  cliquer 0   31  0   187 0   1761
/mydb.nsf/xPublish?OpenAgent&docid=487A3447CFA36BF085257EE400626485 HTTP    GET 302     190 B   141 ms  cliquer 218 16  125 0   0   1620
http://myserver.com/mydb.nsf/dx/test_13col00    HTTP    GET 200 text/html   55.71 Ko    312 ms  cliquer 359 0   0   32  0   1308

A case that doesn't work:
http://myserver.com/mydb.nsf/page.xsp?action=editDocument&documentId=353BA  HTTP    POST    302     244 B   188 ms  cliquer 0   32  0   156 0   156
/mydb.nsf/xPublish?OpenAgent&docid=E0E13322928B8F9685257EE400628B0A HTTP        (Abandonned)        193 B   < 1 ms  cliquer 188 0   0   0   0   156

“发布”按钮中的代码是:

//set status
    if(getComponent("publishLater1").getValue() == "1") {
        pageDocument.replaceItemValue("status", "Scheduled Publication");
    } else {
        pageDocument.replaceItemValue("status", "To Be Published");
    }

    //so we know the document has been saved (for drafts, when cancelled)
    pageDocument.replaceItemValue("hasBeenSaved", "1");

    //init some fields (res_title, ...)
    if(!(pageDocument.hasItem("res_title")) || pageDocument.getItemValueString("res_title")==""){
        pageDocument.replaceItemValue("res_title", buildResTitle(pageDocument.getItemValueString("subject")));
    }

    //set VERKEY AND VERNUMBER if not already set
    if(pageDocument.getItemValueString("VERKEY")==""){
        pageDocument.replaceItemValue("VERKEY", @Unique());
    }
    if(pageDocument.getItemValueString("VERNUMBER")==""){
        pageDocument.replaceItemValue("VERNUMBER", 1);
    }

    //save pageDocument
    pageDocument.save();

    //send to publish agent
    //remove the lock doc
    //unlockDoc(pageDocument.getDocument().getUniversalID());

    //for scheduled publications, a LotusScript agent will do the work
    var res=facesContext.getExternalContext().getResponse();

    if(getComponent("publishLater1").getValue() == "0") {
        // Now load the publish Agent
        var baseUrl = @Left(facesContext.getExternalContext().getRequestContextPath(),".nsf") + ".nsf/"; 
        facesContext.getExternalContext().redirect(baseUrl + "xPublish?OpenAgent&docid=" + pageDocument.getDocument().getUniversalID());
        //res.sendRedirect(xPublish?OpenAgent&docid=" + pageDocument.getDocument().getUniversalID(), false);
    } else {
        //send to the drafts view, to show it has the clock icon in the draft view
        context.redirectToPage("adminDrafts.xsp");      
    } 

我将省去被称为(xPublish)的LotusScript代理程序,但该代码中的重定向是这样完成的:

Print "Location:" + db.Filepath + "/dx/" + res_title

根据IE的http日志,在按钮中运行代码时似乎不太正确,并且它会导致http帖子被放弃,因此,对LotusScript代理的调用也被放弃,而不是重定向用户到新发布的页面。而是将用户重定向到此URL:

http://myserver.com/mydb.nsf/page.xsp?action=editDocument&documentId=353BA

这里的一个大问题是在LotusScript代理中删除了这个页面(草稿版本),因此URL会给出一个错误页面。

如果你想知道为什么发布代码在LotusScipt中,那是因为我们还有一个每天运行的预定代理,并发布将在未来发布的“预定发布”。这是为了避免必须同时维护SSJS和LotusScript代码。

为什么会发生这种情况的任何线索?

更新

好吧,似乎代码工作正常,但是LotusScript代理中的重定向不能完成任务。这就是我用来重定向到刚刚发布的页面的内容:

Print "Location: http://ourserver.com/mydb.nsf/dx/" + res_title

它曾在某一点上工作,但现在它似乎正在引发问题。有趣的是,代理可以正常使用我们从头开始创建的文档,但不适用于在以前版本的应用程序中创建的文档...仍然不知道如何解决这个问题。从LotusScript for xpages进行重定向的方法是什么?

1 个答案:

答案 0 :(得分:0)

好的,我知道了这一切。它仍然有点奇怪,因为它对于新文档运行正常,但对于在先前版本的应用程序中创建的文档不行,但我以错误的方式调用LotusScript代理。

通过查看它是如何在IBM Wiki模板中完成的,我注意到他们以不同的方式调用LotusScript代理,我试过了。事实证明它很有效:调用代码并且重定向没有任何问题。

以下是我现在调用我的代理并进行重定向的方式:

var agent = database.getAgent("xPublish");
var res = facesContext.getExternalContext().getResponse();
agent.runOnServer(pageDocument.getNoteID());    
res.sendRedirect(@Left(facesContext.getExternalContext().getRequestContextPath(),".nsf")+".nsf/dx/"+pageDocument.getItemValueString("res_title"));

正如我所说,不确定为什么我的原始代码停止工作,并且仅在应用程序的早期版本中创建的文档出现问题,但新代码始终适用于所有文档。如果IBM这样做,我想这可能是正确的方式。

那个wiki应用程序里面有很多代码!看看它,以获得一些有价值的代码或获得灵感!!!