Creating documents in Xpages without a Notes Form

While researching for an up-coming project that uses Xpages, I came across this article posted on the IBM developerworks site. My first reaction was that the post was an Xpages intro piece aimed squarely at IBM's expectant hordes given that the Designer client had been recently made free. However after reading through the first few paragraphs - I came across a some information that smashed a pre-conception i had about Xpages: You don't need to have a create a Notes Form in order to create data from an  Xpage to. Huh. Fancy that!

For some mis-guided reason, I had thought that you needed to have an underlying Notes Form with which you would bind each input element on the Xpage to so that the database would know how to create a document. While its true that you can do that - in fact its a way of Xpage enabling an existing Notes application - you don't actually need to do that. With a smidgin' of Server Side JavaScript (SSJS)  it turns out you can create a document from an Xpage without legacy Notes Design resources.

An Xpage Quick Start

In the steps below, Im going to walk through how to create a simple Xpage, with a single input field and allow you to create documents in the underlying NSF. This is similar to the IBM example, only i focus on one component -- creating a document.

Ok, lets get started.
  1. Create a new blank application on your local machine, call it "Test1.nsf".
  2. Go to the Xpages list in the Application navigator and create new blank Xpage. Call it "Main".



  3. Next from the Controls Palette drag and drop an Edit Box control, and a Button control onto your Xpage.
  4. Place the cursor in front of the Edit box, and type "Keyword"
  5. Place the cursor on the button, click the "Properties" Tab in the bottom pane, and change the label text, to "Submit".

Your basic, cut down, no-frills Xpage should look like this.



So now that you've got a form that accepts a single input field, how do you "wire" or connect that field to a notes document? In this Xpage example, we will do this by creating a Request Scoped Variable - which means is a variable that exists on the Server Side once the form is posted to the server -- only, its Scope or the time for which it exist programmatically is limited to the life of the request - in this case the form post to the server - hence s Request Scope Variable. To do this:

  1. Click on the Edit box control on the Xpage, then click the Events tab in the bottom Pane of designer. 
  2. Next select Data under Properties. Select Advanced. From the drop-down list, select Scoped Variable. In the Parameter field, select Request Scope from the list. Finally,enter a variable name, lets call this variable keyword. 






Now comes the SSJS magic. And it deceptively simple, especially if you are already familiar with LotusScript as it shares nearly all of the same class names.

Click the "submit" button, then click the Events Tab in the bottom pane of designer.
Make sure that the onclick is selected (it highlighted by default). Then select Script Editor and make sure that the Server tab is selected (it is by default).
Paste the following code into the box.

var doc = database.createDocument();
doc.replaceItemValue("keyword", requestScope.keyword);
doc.save();
requestScope.keyword= null;


Now, save and preview the form - remembering that you need to add the Anonymous ACL entry in order to preview your application locally.

You should see a simple web form like the one below. Enter a value in the Keyword field, and click submit.

The Xpage is creating a new document everytime you press submit! Nice. Whats that I hear you say? You want proof it is creating documents? Ok then, lets add a document counter to the page.

  1. From the Controls Palette, drag across a Computed field control.
  2. Add the following Javascript under the Properties tab > Value > Javascript:
    return "Number of documents in database: " + database.getAllDocuments().getCount().toFixed()
This JavaScript will return the value of all the documents in the database  (note the Javascript dot notation, but the LotusScript like Class names).

Again, save a preview your Xpage and watch the document count increment each time you create a new keyword. Head over to the Developer works article where they extend a similar example to this and include, editing, deletion and viewing actions - again, all in JavaScript.
:)

Live long and prosper!

So the Lotus community is at its vibrant best right now, with Lotusphere '10 being well underway in Orlando. Doing my best to put aside my FOMO at not being there (yes hello Craig - i know you're *actually* over there), I've been reading through the chatter and i happened across this post regarding IBM's project Vulcan. Most interesting.

IBM is giving its researchers a new pipeline to show off early versions of net-based Lotus collaboration tools.
As part of its annual Lotusphere conference on Monday, the company also provided a peek at what it sees as the future of the business collaboration suite, a thing called "Project Vulcan."
Taking a page from Google Labs, Big Blue's new LotusLive Labs website is designed to spur public feedback (and hype) on LotusLive cloud collaboration technologies while they're still cooking in pre-production.
The project is a joint effort from IBM's Research unit and its Lotus software team. Scheduled to make a beta appearance on the LotusLive Labs in the second half of 2010, Project Vulcan looks to be the most ambitious of the Lotus previews debuting on the website this year.
According to Ed Brill, IBM chief of product management for Lotus software, Project Vulcan represents the future direction for Lotus Notes. It's described as combining email, profiles, calendars, and social analytics in one spot, and it will use analytics engines and business-specific scenarios to make collaboration more relevant and focused.
It also promises to include developer-friendly services and APIs.
Shades of Google Wave, with a bit of IBM's analytics oomph behind it. But user interface-wise, it's all Facebook - judging by the "conceptual representation" graphic Mills supplied:
"One of the key evolutionary thoughts in IBM Project Vulcan is to move from what we currently refer to as 'linked value' across the IBM portfolio to the notion of 'loosely-coupled' services," Brill wrote in his blog. "This makes sense in an increasingly-expected hybrid environment, and will simplify deployment and adoption of collaboration and productivity within your organization.  Web services, xPages, HTML5, RESTful APIs, will all be tools in pushing Project Vulcan forward."
Other LotusLive previews in the pipeline include Slide Library, a collaborative way to share presentation resources; Event Maps, an interactive way to organize and browse conference schedules; Collaborative Recorded Meetings, a service that records and transcribes meeting presentations; and Composer, which lets users create new applications by mashing up existing services from the web, email, and collaboration tools.
The four can be previewed now by signing up for IBM's LotusLive Labs website. ®




Blogging: Epic Fail

So, admittedly my first attempt and getting this blog up and running was an *epic fail*. Although to be fair, I did start a new role in early December (after 7 weeks of swanning around and generally unplugging from the yellow-bubble) and then there was the whole Christmas period to contend with.

Thankfully both my Liver and my desire to continue this blog emerged intact from the festive season, and so without further ado -- I bring you my first post of 2010. An epic fail of sorts.... (sniggers behind IBM's back)