This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Jan 27, 2012, 6:20 PM
26 Posts

Dynamic Datasource?

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 3
How do you create a dynamic data source?
 
I found this bit of code:
 
http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Computed_Datasource_Application
 
 
But it does not seem to work.  In fact it does not even make any sense.   They are returning the second element of the array which is the filename.
 
When I try this I get an exception:
 
Unable to open database: directory\filename.nsf
Database directory\filename.nsf cannot be opened 
Jan 27, 2012, 7:58 PM
1 Posts
Re: Dynamic Datasource?
 Hey Bruce,
 
It's all about getting the syntax down.
 
For dominoDocument and dominoView data sources, the databaseName uses the following syntax:
 
servername!!directory\subdirectory\db.nsf 
 
Now, you only need the "servername" and the double-exclamation separators if your target Domino server is remote/external to the one serving your XPage.
 
In other words, if you're XPage is on "DominoServer1" and want to access a NotesDatabase on "DominoServer2", the databaseName would be:
 
DominoServer2!!db.nsf
 
If your XPage is on "DominoServer1" and you want to access a NotesDatabase on "DominoServer1", the databaseName would be:
 
db.nsf
 
Once you get this down, you can do some pretty cool things. For example, you can allow your users to "select a data source" via a combobox on your XPage, and have either the dominoDocument or the dominoView databaseName point to the combobox value.
 
Here's a quick example of a single XPage (Home.xsp) that has dynamic dominoDocument and dominoView  databaseNames that point to two external databases. This XPage can point to two different NotesDatabase data sources (ds1.nsf & ds2.nsf) for creating or reading NotesData. Here's the XSP markup:
 
<?xml version="1.0" encoding="UTF-8"?>
<xp:view
xmlns:xp="http://www.ibm.com/xsp/core">

<xp:div
id="actionbar">
<xp:comboBox
id="database"
value="#{sessionScope.database}"
defaultValue="demo\ds1.nsf">
<xp:selectItem
itemLabel="Data Store 1"
itemValue="demo\ds1.nsf">
</xp:selectItem>
<xp:selectItem
itemLabel="Data Store 2"
itemValue="demo\ds2.nsf">
</xp:selectItem>
<xp:eventHandler
event="onchange"
submit="true"
refreshMode="partial"
refreshId="container_data">
</xp:eventHandler>
</xp:comboBox>
</xp:div>

<xp:div
id="container_data">
<xp:panel
id="panel_newdocument">
<xp:this.data>
<xp:dominoDocument
var="newdocument"
databaseName="#{javascript:getComponent('database').getValue()}">
</xp:dominoDocument>
</xp:this.data>
<xp:table>
<xp:tr>
<xp:td
styleClass="label">
<xp:label
for="title"
value="Title" />
</xp:td>
<xp:td
styleClass="input">
<xp:inputText
id="title"
value="#{newdocument.title}" />
</xp:td>
</xp:tr>
<xp:tr>
<xp:td
styleClass="label">
<xp:label
for="description"
value="Description" />
</xp:td>
<xp:td
styleClass="input">
<xp:inputTextarea
id="description"
value="#{newdocument.description}" />
</xp:td>
</xp:tr>
<xp:tr>
<xp:td
colspan="2"
styleClass="action">
<xp:button
value="Submit"
id="submit_newdocument">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete"
immediate="false"
save="true">
<xp:this.action>
<xp:openPage
name="/Home.xsp"></xp:openPage>
</xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:td>
</xp:tr>
</xp:table>
</xp:panel>

<xp:viewPanel
rows="30"
id="viewPanel1">
<xp:this.facets>
<xp:pager
partialRefresh="true"
layout="Previous Group Next"
xp:key="headerPager"
id="pager1">
</xp:pager>
</xp:this.facets>
<xp:this.data>
<xp:dominoView
var="view_documents"
viewName="documents"
databaseName="#{javascript:getComponent('database').getValue()}">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn
columnName="created"
id="viewColumn1">
<xp:viewColumnHeader
value="created"
id="viewColumnHeader1">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn
columnName="title"
id="viewColumn2">
<xp:viewColumnHeader
value="title"
id="viewColumnHeader2">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn
columnName="description"
id="viewColumn3">
<xp:viewColumnHeader
value="description"
id="viewColumnHeader3">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn
columnName="author"
id="viewColumn4">
<xp:viewColumnHeader
value="author"
id="viewColumnHeader4">
</xp:viewColumnHeader>
</xp:viewColumn>
</xp:viewPanel>

</xp:div>

</xp:view>
 
Update: here's an online demo of this page in action: http://guru.gbs.com/demo/ddd.nsf/Home.xsp (I'll most likely clean up the UI later...) -- @ChrisToohey 
 
Now, this is a very basic example (and quite ugly too - I didn't take the time yet to style it, nor clean up the viewPanel, etc.), but it'll give you an idea of what you can do with dynamic  dominoDocument and dominoView data sources.
 
If you have any problems with this, please let me know!
 
-Chris 
http://www.dominoGuru.com 
Jan 27, 2012, 8:08 PM
586 Posts
Re: Dynamic Datasource?
 I think there's something about computing the database on the XPages CheatSheet at xpagescheetsheet.com.  I've been doing something like this: to get a hold of a database on the same server in the same subdirectory.
 

var path = database.getFilePath().split(database.getFileName())[0]

return path + "dbname.nsf"
 
I've not really reached out to a remote server I don't think.  But if you do Trusted access needs to be setup in the server configuration. 
 
Other then that...  ditto whatever Toohey said.  :-) 
Jan 31, 2012, 1:11 PM
26 Posts
Re: Dynamic Datasource?
Well I posted this response yesterday and am not sure what happened but it is not here.
 
 
Exactly what should my function return?
 
"server!!path\filename"
 
 
If so I have tried that and it does not seem to work.
 
 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal