2
votes

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

1 Answers

2
votes

There are a couple of potential aspects at work here. I identified something about datasource computation settings time ago and covered in sessions at Connect, Engage and delivered in the "Marty, You're Just Not Thinking Fourth Dimensionally" TLCC webinar (look at the last one of 2016 here). If a datasource is attached to an XPage, it gets loaded during the createView method of the ViewHandler, which runs before beforePageLoad. If it's attached to a component on the XPage (Panel, Custom Control etc), it gets calculated when that component's properties get calculated, during beforePageLoad. See slide 10 on the slides.

Another element worth bearing in mind is you're setting documentId property, but not setting ignoreRequestParams. So what's likely to be happening (again, it's worth watching that webinar) is that in beforePageLoad you're getting the document you are specifying, but in beforeRenderResponse the datasource is being told to look at the request parameters, which are blank, so a new document is being created. Obviously you can't get the backend Document for a new document - because it's not been saved yet, so doesn't exist.