什么可能使context.redirectToPage行为不同

时间:2013-03-21 19:40:50

标签: xpages xpages-ssjs

我有两个不同自定义控件的按钮,在他们的onclick事件中调用context.redirectToPage()。在一个实例中,这导致HTTP重定向(HTTP状态为302)到期望的URL(即,头部位置= http://frontend.company.com/path/to/file.nsf/myXpages.xsp?documentId=C699C5D6E81721EA85257A2F00683319&openDocument)。在另一个实例中,它返回如下标记:

<script>window.location.href='http://backend.company.com:81/path/to/file.nsf/myXpage.xsp?documentId=C699C5D6E81721EA85257A2F00683319&openDocument'</script>

两个实例都有submit = true,refresh = complete和immediate = true。两者都有正确执行的客户端脚本和在重定向调用之前执行的几行SSJS。我可以想到的唯一区别是,返回脚本的按钮位于(xe:对话框)内。

你们中的精明人员会注意到为什么这对我来说是一个问题,因为我们的Domino服务器是在反向代理之后。凡人都没有直接访问Domino的权限,因此脚本标记中生成的URL将无效。

有没有人知道如何从第二个按钮获取302重定向的首选行为,甚至是让它使用正确的URL的方法?或者甚至阐明为什么行为会有所不同?

谢谢,

编辑:为context.redirect()生成脚本标记的按钮的代码:

<xp:button
                id="errorReloadButton"
                value="Reload Page">

                <xp:this.rendered><![CDATA[#{javascript:whichButton == "reload"}]]></xp:this.rendered>
                <xp:eventHandler
                    event="onclick"
                    submit="true"
                    refreshMode="complete"
                    immediate="true">
                    <xp:this.action>
                        <xp:actionGroup>

                            <xp:executeScript>
                                <xp:this.script><! [CDATA[#{javascript:sessionScope.remove("errors");
var c = getComponent("errorDialog")
c.hide();
var redirectTarget = view.getPageName() + '?documentId=' + compositeData.docID + '&openDocument';
context.redirectToPage(redirectTarget,true);
}]]></xp:this.script>
                            </xp:executeScript>
                        </xp:actionGroup>
                    </xp:this.action>
                    <xp:this.script>
                        <xp:executeClientScript>
                            <xp:this.script><![CDATA[setClean("#{javascript:compositeData.docID}");
XSP._setDirty(false,"");]]></xp:this.script>
                        </xp:executeClientScript>
                    </xp:this.script>
                </xp:eventHandler>
            </xp:button>

编辑2:正确强制302重定向的按钮源:

<xp:button
        id="cancelButton"
        value="Cancel"
        rendered="#{javascript:compositeData.documentDataSource.isEditable()}">
        <xp:eventHandler
            event="onclick"
            submit="true"
            refreshMode="complete"
            onError="handleError(arguments[0],arguments[1])"
            immediate="true">
            <xp:this.action>
                <xp:actionGroup>

                    <xp:executeScript>
                        <xp:this.script><![CDATA[#{javascript:var xdoc:NotesXspDocument = compositeData.documentDataSource;
if(xdoc.isNewNote()){  
return;
}
var doc:NotesDocument = xdoc.getDocument(false);
/* more code here, not relevant to this */
var docid = doc.getUniversalID();
context.redirectToPage(view.getPageName() + '?documentId=' + docid + '&openDocument')}]]></xp:this.script>
                    </xp:executeScript>
                </xp:actionGroup>
            </xp:this.action>



            <xp:this.script>
                <xp:executeClientScript>
                    <xp:this.script><![CDATA[setClean("#{javascript:docId(compositeData.documentDataSource)}");
if(#{javascript:compositeData.documentDataSource.isNewNote()}){
popPageStack();
return false;
}]]></xp:this.script>
                </xp:executeClientScript>
            </xp:this.script>
        </xp:eventHandler>
    </xp:button>

1 个答案:

答案 0 :(得分:1)

有两种方法可以解决您的问题:您可以将重定向硬编码到新网址,例如。

 facesContext.getExternalContext().redirect( "http://stackoverflow.com" );

或者您必须使用反向代理修改HTTP响应。

最后一个选项是更好的选项,因为这也会影响所有部分刷新。 还有一个额外的HTTP标头 X-XspLocation ,其中包含必须修改的目标网址。

修改

该脚本位于(xe:对话框)中。 - &gt;这就是原因。我的错,我还没看过这个信息。 xe:dialog 中的事件将被强制进行部分刷新,否则它们将无法在“对话框内”工作。这会影响所有重定向,它们将始终返回带有目标的Javascript和 X-XspLocation 标头。

在大多数情况下,返回的Javascript将不会被执行,因为响应中的标题会更早解析(并强制重定向)。

如上所述,最好的方法是更改​​反向代理配置。或者,您可以更改服务器以使用外部名称。或者在按钮代码中返回外部地址。