So far in our application we have shown
you how to display the current documents in the database and how to edit
existing person documents. Over the next few parts we are going to add
in some controls that will allow you to create new documents if you have
the [PhonebookEditor] role in the ACL of your application.
Creating a document is an action so
we need to add in an actionbar and action button to the design of our application.
I’m going to create my action button in the content_location custom control
just above the pager that I’m using for the list of people at a location.
Instead of building the action button
from scratch I’m going to reuse some code form the content_person custom
control. Start by pening that control and switching to the source view.
You’ll need to find the xp:panel tag that contains the styleClass of ‘lotusActionBar’
and copy everything between and including those xp:panel tags to the clipboard.
Then open your content_Location custom
control, switch to the source view and find the <xp:pager> tags,
add in a new line just above it and then paste in the contents of your
clipboard. If you switch back to design view you should see your new panel
in the design containing the buttons that we had created for the content_person
Delete the last two buttons in the panel
we don;t need them here and then look at the properties for the ‘Edit Document’
link. The first thing we will change is the label so that it reads ‘Create
Next we need to change when the button
is visible. Change the computed value for the visible property to
var s1 = context.getUser().getRoles();
var s2 = "honebookEditorquot;;
if (@Contains(s1, s2) == @True())
And the last thing we need to do is
change what happens when the user clicks on the action. Switch to the ‘Events’
tab for the link and in the ‘onClick’ event remove the current action and
then click on the ‘Add Action’ button to add a new action.
We are going to create a basic action
that will open the ‘Person’ Xpage and set the target document to ‘New Document’.
If you save and preview your XPage and
you have the correct role you should now see your ‘Create Person’ button.
Clicking the button will bring you to
the Person XPage that we designed earlier with a blank person document
loaded up and already in edit mode.
In the next part we’ll adjust the person
document so that the uneditable fields are editable when it detects your
creating a new document.