Reputation: 33
In my XPage I need to set a data source (Domino document)
I try to do it as follows:
<xp:this.data>
<xp:dominoDocument var="requestDocument" action="openDocument" databaseName="#{javascript: print('db ok'); return database.getFilePath();}"
documentId="#{javascript:
print('heloooo');
var conclusion = database.getDocumentByUNID(doc_source.getDocument().getParentDocumentUNID());
var oConclusion = new OsnovaUI_document(conclusion);
var requestDoc = oConclusion.getMainDocument();
print('docID: ' + requestDoc.getUniversalID());
return requestDoc.getUniversalID();
}">
</xp:dominoDocument>
</xp:this.data>
The thing I've noticed is that code section in documentId
doesn't get executed. At all. That's why I've put heloooo
in there. However, the databaseName
works as expected. In console I always see
09.03.2020 00:52:11 HTTP JVM: db ok
But not heloooo :(
What am I doing wrong? Thanks in advance
Upvotes: 3
Views: 134
Reputation: 21709
Change documentId to be computed on page load ($) and not dynamically (#):
<xp:this.data>
<xp:dominoDocument var="requestDocument" action="openDocument">
<xp:this.documentId><![CDATA[${javascript:
var conclusion = database.getDocumentByUNID(doc_source.getDocument().getParentDocumentUNID());
var oConclusion = new OsnovaUI_document(conclusion);
var requestDoc = oConclusion.getMainDocument();
print('docID: ' + requestDoc.getUniversalID());
return requestDoc.getUniversalID();
}]]></xp:this.documentId>
</xp:dominoDocument>
</xp:this.data>
The databaseName is not required if the database is itself.
Upvotes: 2
Reputation: 15739
The most likely cause is ignoreRequestParams
is not set to true
. Unless you set that, the data source is retrieving all specifics about which document to edit based on the URL query string parameters (the HTTP request parameters). As a result, the URL query string parameters take precedence, and in the case of nothing being set, that means "use a new document". If you've defined that the URL query string parameters should take precedence, running your code to merely ignore it afterwards is inefficient. As a result, action="openDocument"
is also being ignored - if you have a docId in the query string it will open that, otherwise it will create a new document.
documentId
can only get processed once, when the page first loads. Depending on whether the datasource is bound to a panel or an XPage / Custom Control, it will run before the beforePageLoad
event as well. So runtime binding (#{javascript:...
) has no effect. ${javascript:...
will avoid confusion.
Error handling may help identify if there is an error. XPages OpenLog Logger is one of the most pervasive (disclaimer, I'm the author) https://openntf.org/main.nsf/project.xsp?r=project/XPages%20OpenLog%20Logger.
Upvotes: 3