Data Source in Custom Controls vs. in XPages and BeforeRenderResponse Event

时间:2017-06-19 13:56:04

标签: xpages xpages-ssjs

I have some strange behavior, lets take a look at the following examples:

The first example without any problems:

XPage (with an included datasource)

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">

    <xp:this.data>
        <xp:dominoDocument var="docData" 
            formName="frmPrototype" 
            action="openDocument"
            documentId="3DEF64BFAD6E1F32C12580B8003CB18F">
        </xp:dominoDocument>
    </xp:this.data>

    <xc:ccModule></xc:ccModule>

</xp:view>

Custom Control "ccModule"

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">

    <xc:ccSubModule></xc:ccSubModule>

</xp:view>

Custom Control "ccSubModule"

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:this.beforePageLoad><![CDATA[#{javascript:print("beforePageLoad");
print(docData.getDocument().getUniversalID());
print(docData.getItemValueString("Subject"));}]]></xp:this.beforePageLoad>

    <xp:this.beforeRenderResponse><![CDATA[#{javascript:print("beforeRenderResponse");
print(docData.getDocument().getUniversalID());
print(docData.getItemValueString("Subject"));}]]></xp:this.beforeRenderResponse>

</xp:view>

Output as expected:

enter image description here

Now the slightly different second example:

In this example the data source was moved to the ccModule custom control.

XPage

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">

    <xc:ccModule></xc:ccModule>

</xp:view>

Custom Control "ccModule" (with an included datasource)

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">

    <xp:this.data>
        <xp:dominoDocument var="docData" 
            formName="frmPrototype" 
            action="openDocument"
            documentId="3DEF64BFAD6E1F32C12580B8003CB18F">
        </xp:dominoDocument>
    </xp:this.data>

    <xc:ccSubModule></xc:ccSubModule>

</xp:view>

Custom Control "ccSubModule"

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:this.beforePageLoad><![CDATA[#{javascript:print("beforePageLoad");
print(docData.getDocument().getUniversalID());
print(docData.getItemValueString("Subject"));}]]></xp:this.beforePageLoad>

    <xp:this.beforeRenderResponse><![CDATA[#{javascript:print("beforeRenderResponse");
print(docData.getDocument().getUniversalID());
print(docData.getItemValueString("Subject"));}]]></xp:this.beforeRenderResponse>

</xp:view>

Output:enter image description here

It seems, that now the data source isn't available anymore in the beforerenderrepsone event?

Any idea what is going on here?

1 个答案:

答案 0 :(得分:2)

这里有几个潜在的方面。我在很久以前就确定了有关数据源计算设置的内容,并在Connect,Engage的会话中进行了介绍,并在“Marty,你只是不考虑第四维度”的TLCC网络研讨会中进行了介绍(查看2016年的最后一篇here)。如果数据源附加到XPage,它将在ViewHandler的createView方法中加载,该方法在beforePageLoad之前运行。如果它附加到XPage(面板,自定义控件等)上的组件,则会在beforePageLoad期间计算该组件的属性时计算。请参阅幻灯片上的幻灯片10。

值得注意的另一个因素是,您要设置documentId属性,而不是设置ignoreRequestParams。所以可能发生的事情(再次,值得观看网络研讨会)是beforePageLoad你得到你指定的文件,但在beforeRenderResponse中,数据源被告知查看请求参数是空白的,因此正在创建 new 文档。显然你无法获得新文档的后端文档 - 因为它尚未保存,所以不存在。