Search code examples
xpagesxpages-ssjs

setting database for xp:dominoDocument via properties file


I would like to set the location of a database for the xp:dominoDocument data Property via SSJS and a properties file:

<xp:this.data>
        <xp:dominoDocument var="document1" action="openDocument"
            formName="album   -   $f-album" computeWithForm="both"
            concurrencyMode="force"
            databaseName="#{javascript:datasource.getString('DB_FILEPATH')}">
            <xp:this.documentId><![CDATA[#{javascript:context.getUrlParameter("UNID")}]]></xp:this.documentId>
        </xp:dominoDocument>
    </xp:this.data>

The datasource property contains e.g.

DB_FILEPATH=Bildr6Phase10Data.nsf

and is available via

<xp:this.resources>
        <xp:bundle src="/datasource.properties" var="datasource"></xp:bundle>
    </xp:this.resources>

The code above will cast the error:

com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript computed expression
Error while executing JavaScript computed expression
Script interpreter error, line=1, col=12: [ReferenceError] 'datasource' not found

However if I try:

<xp:text escape="true" id="computedField1"
        value="#{javascript:datasource.getString('DB_FILEPATH')}">
    </xp:text>

I get the value from the property. What am I doing wrong?


Solution

  • Instead of a Computed Field, try logging datasource.getString('DB_FILEPATH') in beforePageLoad and beforeRenderResponse. Also log out a message in databaseName property. I would expect the databaseName property to be required when the component tree is first loaded. However, I would not be surprised if the resource string is loaded later.

    An alternative may be to use xsp.properties file. There is code on how to retrieve a property from xsp.properties in XPages OpenLog Logger.