dominoGuru.com
Your Development & Design Resource
XPages Primer: Creating a New Contact in a Domino Directory
05/24/2010 01:47 PM by Chris Toohey
One of the greatest benefits of using IBM Lotus Notes Domino XPages is that it naturally allows for the separation of User Interface and Target DataStore. To illustrate, we'll use an XPage to create a simple User Registration form for a Domino Directory!
To kick off this process, we'll create a new Domino Directory (local is fine, no need for a server for this demo build). I named my new local Domino Directory aldir.nsf. Next, I create a new blank NotesDatabase, which I named alsite.nsf. We'll be adding our XPages Design Element in the alsite.nsf, which will communicate directly to the aldir.nsf Domino Directory. Again, running this on local is fine...
The XPage, which I'm naming index.xsp, will consist of -- for the purposes of this demo -- a simple user registration form.
The index.xsp Source Code:
- <?xml version="1.0" encoding="UTF-8"?>
- <xp:view xmlns:xp="http://www.ibm.com/xsp/core">
-
- <xp:this.data>
- <xp:dominoDocument var="userreg" databaseName="aldir.nsf"
- formName="Person">
- </xp:dominoDocument>
- </xp:this.data>
-
- <fieldset class="userreg">
- <label for="firstname">First Name</label>
- <xp:inputText id="firstname" value="#{userreg.firstname}">
- </xp:inputText>
- <br />
- <label for="lastname">Last
Name</label>
- <xp:inputText id="lastname" value="#{userreg.lastname}">
- </xp:inputText>
- <br />
- <label for="internetaddress">Email Address</label>
- <xp:inputText id="internetaddress" value="#{userreg.internetaddress}">
- </xp:inputText>
- <br />
-
- <xp:text escape="true" id="type" value="#{userreg.type}"
- rendered="false">
- </xp:text>
-
- <xp:button value="Register" id="userreg_submit">
- <xp:eventHandler event="onclick" submit="true"
- refreshMode="complete">
- <xp:this.action>
- <xp:actionGroup>
- <xp:modifyField name="type" value="Person">
- </xp:modifyField>
- <xp:saveDocument></xp:saveDocument>
- </xp:actionGroup>
- </xp:this.action>
- </xp:eventHandler>
- </xp:button>
- </fieldset>
-
- </xp:view>
The above code -- sans any styling -- creates the following fully-functional XPages-based Form:
Lines 4-8 define our target Data Source, which is our aldir.nsf Domino Directory.
The only other real gotcha to point out here is at line 33, where
the Register button uses an actionGroup
to first set the
non-rendered type InputField to Person before submitting the
request to create a new NotesDocument in the aldir.nsf Domino
Directory. That is simply due to the target Domino Directory Person
NotesDocument requiring that the type NotesItem be set to
"Person" before it will be displayed in the People View. The
type NotesItem has no particular functionality specific to the XPage
User Registration Form.
To really make this a reusable solution, you can take the XPages XML markup above and create a Custom Control Design Element, which could be used by any other Custom Control or XPage Design Element in your NotesDatabase Design.
See my post on XPage Custom Controls in IBM Lotus Notes and Domino from the other day for more details.
... and that's it! I can use this User Registration Form (or via a Custom Control) in my XPages-based application to create NotesData in other NotesDatabases with literally zero modifications to the target NotesDatabase design.
Amazingly powerful stuff here, and certainly something that while doable using traditional IBM Lotus Notes and Domino development techniques, XPages makes it a simple RAD operation!