PermaLink XPages - Undocumented Feature that will help you build Plug-n-Play Custom Controls05/07/2009 07:06 AM
Domino 8.5
When building Custom Controls for XPages, the ultimate goal is to make the Custom Control plug-n-play.  You want to be able to drop the custom control on any XPage and have it interact with the XPage seamlessly.

Being a Design Partner, I have been working with XPages since the pre-beta versions.  Prior to that I was Design Partner for the Lotus Component Designer.  So to come across a new feature is exciting....  

I recently wanted to make a custom control completely independent of the XPage it was on (see this custom control).  Yet I still needed to grab some values from the datasource for the XPage the control is placed on.  The issue is that the XPage datasource name is set by the developer and I could not see a way to determine the datasource name without requiring the end developer to place additional code on their XPage to support my custom control.

Looking through the Request Scope variables on the page at runtime, I found that there is a variable present on every XPage called currentDocument.  Sure enough, it was of NotesXSPDocument type and was set to the current document for the XPage.  So I could now have access to any data on the document I needed without knowing the datasource name.  

For example, if I wanted to find out what the Form name for the document opened in the XPage that my custom control was on, I could use the following code:
theForm=currentDocument.getForm();

or to get the backend NotesDocument and determine the Document unique ID:

doc=currentDocument.getDocument();
docUNID=doc.getUniversalID();


I checked with the XPages Chief Architect, Phil Riand, and this object will be supported in future releases and will be documented.  So it is safe to use this feature in your applications.

Enjoy....

-John


Technorati:
This page has been accessed 2309 times. .
Comments :v

1. Jens Polster05/07/2009 08:05:04 AM
Homepage: http://www.DomBlog.de


Thanks, this is excellent news. I have been using currentDocument but wasn't sure if it was safe.

Btw: Thanks for your many contributions in the XPages area. Really appreciated!




2. David Leedy05/07/2009 08:23:27 AM
Homepage: http://www.lotusnotebook.com


That's awesome! Great find! I'm glad it's going to be documented.

I second Jens's comment about really appreciating your contributions!




3. barry mcgovern05/08/2009 02:54:05 AM


Great find! I have been creating all sorts of work arounds for this.

I wonder how it will work if you have multiple document references on one page.




4. John Mackey05/08/2009 04:10:37 AM
Homepage: http://www.jmackey.net


@Barry, it seems to default to the main or first datasource on the page. I was thinking about the exact same thing and was hoping for an array when there are multiple datasources.

Place the following in a computed field on the form and you'll see the keys available in the requestScope: requestScope.keySet()

I'm still looking for a simple solution to that. If anyone has any ideas, please post your suggestions...




5. Nick Hopkins05/13/2009 01:19:49 AM


Hi John,

Having read your blog & examined your examples I launched my first xpage application this week.

Without your guidance I would have launched sometime around Christmas!

This is just an unrelated post to say thank you very much for all of your help

Rgds

Nick




6. cao shangping09/01/2009 01:39:33 AM


thank you




7. Barry10/23/2009 04:09:54 AM


Hi John,

Just wanted to document a problem here that I found with the currentDocument object in 851. It appears to have a bug when used inside a facet.

Here's the link to the entry I posted in the 8.5 forum.
{ Link }

I fell in love with this property and now I'm getting burned by it. Ugh - the dangers of using an undocumented feature.




Search
Partner with us
Need help on your XPages projects?

Talk to the experts! Read more...
XPage Examples
By Category
About Me
Downloads
My Links
Monthly Archive
Powered by
Blogsphere
Lotus Domino ND7 RSS News Feed RSS Comments Feed Geo URL netcraft RSS Validator Lotus Geek Chris. A. Brandlehner OpenNTF BlogSphere