Learning XPages Part 46 : Setting Up To Add Edit And Delete Locations

Our application is nearly complete on the
XPages side. A normal user can select a location, look at all the people
in that location, select a person and look at all the details for that
person.  A user with the PhonebookEditor role also has the ability
to create new person records, edit existing person records and deleted
person records. All that’s left is to give the phonebook editor a way to
add, edit and delete location documents.

There are a couple of things that need
to be done to our application, we need to create a list of the locations
that allows the PhonebookEditor the ability to select a location and instead
of being brought to a list of people within that location be brought to
an XPage that is linked to the location’s notes document so that they can
edit or delete it just like a person’s document. We’ll also need a ‘Create’
action to allow them to create a new document.

To add this functionality to the application
I have created two new XPages, one called LocationAdmin and the other called
LocationEdit. To create them I just made two copied of an existing XPage
and renamed them as required.  I then created two new custom controls
called content_LocationAdmin and content_LocationEdit. Currently the source
of the custom controls are pretty much blank containing a single panel
with the ‘lotusContent’ styleClass :

<?xml version="1.0"
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"&gt;
       <xp:panel id="lotusContent"


Returning to the two new XPages I opened
each of them in turn and replaced their current content_ custom control
with the appropriate new custom control. By reusing code I had done to
create the other XPages in the application I was able to quickly create
the two new Xpages so that they would have the correct layout and look
and feel.

I also need to give the phonebook editor
a way to access the ‘Location Administration’ section of the application.
I had a couple of options here, I could create a whole new menu on the
left sidebar for ‘Administration’ or I could just add a link into the existing
menu. I have decided to go with the latter option so open up the sb_LocationList
custom control and I’ll show you how I added it.

Currently in the source view of sb_LocationList
the start of the menu looks like this

A picture named M2

I’m going to add the administration
link in just where the red line is so I’m going to drag in a new panel
and then switch back to the source view and make sure it is positioned
correctly. I have also given it a styleClass of ‘lotusMenuSection’ and
inside the panel I have added an unordered list with some placeholder text

A picture named M3

If we save and preview our XPage at
this stage we’ll see the new section in the menu

A picture named M4

Now I don’t want this section of menu
to appear unless the person has the PhonebookEditor role in the ACL so
select the the new panel we have created and in the properties click on
the diamond beside the ‘Visible’ property and select ‘compute value’.  In
here we will add in our JavaScript to see if the person has the role or

NOTE : Replace { and } around PhonebookEditor
with square brackets if your coping the below code.

var s1 = context.getUser().getRoles();
var s2 = "{PhonebookEditor}";

if (@Contains(s1, s2) == @True())
       return true;
} else
       return false;

When you use the visible property on
the panel and it evaluates as false then the entire panel and it’s contents
are not sent to the browser. This is a great way of hiding entire sections
of web pages till they are needed.

Now we’ll drag in a link control form
the controls pane to where the palceholder text is. You can delete the
placeholder text also. I’ve given my link a lable of ‘Edit Locations’ and
in the link properties I’m goingto do a simple ‘Open Page’ and point it
to the ‘LocationAdmin’ XPage.

A picture named M5

If we now save the control and open
our Xpages application in the browser, making sure we are logged in with
the role we should see our new link.

A picture named M6

Clicking the link will bring us to the
LocationAdmin Xpage which should be blank right now. We’ll build that in
the next part.

Tagged with: , ,
Posted in None
%d bloggers like this: