Learning XPages Part 24 : Linking to the Person document.

We now have a simple XPage to display a
persons information so in this section we will link to the XPage and pass
in a document UNID so that it knows which document to open.

Lets open up the content_location custom
control. You should see the table that we create in a previous part with
the repeat control inside the table so that each row of the table is repeated.
When linking one page to another there are a couple of different ways that
we can do it. For the phonebook I’d like the user to be able to click anywhere
on the row of the table to bring them into the person document. I could
convert one of the computed fields on the table into a link but that would
require the user to know they have to click only on the link, by allowing
them to click anywhere on the table it will be easier for the user.

What I’m going to do is add an ‘onClick’
event to the table row. Switch to your source view and find and click on
the <xp:tr> tag that appears inside the repeat control.

A picture named M2

In the properties box below you will
need to go to the ‘All Properties’ tab and give the row an ID.

A picture named M3

you should see your XPage source update
to reference the new ID

A picture named M4

The reason we have to do this is so
that the onClick event has something to latch onto. Without the ID the
table row cannot be referenced by our event. With the <XP:TR> still
selected lets have a look at a new section of the Domino Designer that
we have not touched on yet. The ‘Events’ section. You’ll find it as a tab
next to the ‘Properties’ section.

A picture named M5

The events section will show you all
the possible events that you can associate with a XPage control. We are
interested in the onClick event for this particular task so select that
event and have a look at the right side of the tab.

A picture named M6

You will see that we have the ability
to write JavaScript code for the client side or the server side and on
the server side we can also select some of the simple actions that IBM
have provided for us. Lets try a simple action. Click on the ‘Add Action’
button.

A picture named M7

A dialog box will appear and will actually
default for the task that we have in mind. We want to open a different
XPage so we select the name of the XPage and we wnat to open the document
for reading so set the target document as ‘Open Document’, there are also
options for for ‘Edit Document’ and ‘Create Document’. All we have to do
now it tell it what the document ID is. We will compute this value so select
the diamond and choose ‘Compute Value’ and in the script dialog box we
will use the following code.

A picture named M8

If you remember we are inside a repeat
control and rowData is the variable that we can use to refer to the current
entry in the repeat collection that we are working with. rowData.getUniversalID();
returns the UNID for the current document and if we save our XPage and
then preview it in the web browser you will now be able to click on a name
in the table and it will load in the ‘Person’ XPage and show you their
details.

The URL bar in your web browser will
show you your simple action and the DocumentID that your working with.

A picture named M9

In the next part I’ll rewrite the onClick
action to put this information into the sessionScope and then use the values
from there in the person xPage instead.

Tagged with: , ,
Posted in None

Learning XPages Part 23 : Adding Data Fields To The Person Document

Now that we have our new XPage and custom
control created lets add some content to it. Open up your content_person
custom control again and lets get started.

Because we are associating this XPage
with a document we will need to tell the XPage which form we are using
so that it can determine what fields are available. To do this we setup
a new data source for the XPage, Go to the root node in the outline view
and in the properties section select the ‘Data’ properties tab. Click on
the ADD button but instead of selecting a ‘Domino View’ like we did in
earlier parts of tutorial we will select a ‘Domino Document’ and then select
the ‘Person’ form from the current database.

A picture named M2

Now that we have told the XPage where
to find the fields that it has access to we can see then in the ‘Data’
pane in Domino Designer. To access then have a look at the ‘Controls’ pane,
you should see a drop down arrow, select it and you can choose the data
pane.

A picture named M3

A picture named M4

You should now see your data source
and all the fields that are available.

Lets put them on to our XPage, we’ll
worry about formatting them a little later but for now I’d like to just
get them onto the Xpage so that I can show you how to link to the page.
In the data view select ALL the fields and then just drag them all on to
the XPage. The Domino Designer will automatically create a table with labels
and input fields.

A picture named M5

Lets save our custom control but we
can’t preview the Xpage just yet because we have not told it which document
to open. We’ll cover that in the next part.

Tagged with: , , ,
Posted in None

Learning XPages Part 22 : Creating The User Document

So far our XPages Phonebook application
is really starting to come together, we have designed out layout, shown
you how to display information from a view in the Domino backend on the
XPage using a repeat and also shown how to restrict the view to a single
category. Over the next few parts we will explore the display of a notes
document in the XPage and also explore a different way of linking one XPage
to another without having to pass parameters on the URL like we did to
link the sidebar to the single location XPage.

Lets start by creating a brand new XPage
and Custom Control. Just like we did for the single location XPage and
content_Location custom control we are going to do a little component reusing
by copy/pasting some existing design documents and renaming them. Start
off by copy/pasting the content_Location custom control and then use the
F2 key to rename it to content_Person. Once it’s renamed go into the source
view and remove everything except the ‘lotusContent’ panel, I have added
some additional place holder text so mine now looks like this :

A picture named M2

Save and close it and then go to the
XPages view in the design and copy/paste one of the existing XPages and
press F2 to rename it to ‘Person’. Now go into the source of the XPage
and look for the ‘lotusMain’ DIV and change the reference to the existing
custom control to your new custom control. Below I originally copied my
‘Location’ XPage and then changed the reference to the content_Location
custom control.

A picture named M3

A picture named M4

If we save and close the ‘Person’ XPage
at this stage and preview it you should now see the OneUI layout that we
have created and the place holder text appearing in the main part of the
page.

A picture named M5

Now that we have our new XPage and custom
control setup in the next part we’ll associate it with a notes document

Tagged with: , ,
Posted in None

Learning XPages Part 20 : Restricting The Repeat To A Single Category

At the moment our location XPage shows
us all the entries in our categorized view. In this part we are going to
restrict which category is displayed in the repeat control by passing a
variable in on the URL in the format of http://demosite/xphone.nsf/location.xsp?location=Dublin.

To retrieve the variable passed in one
the URL I am going to use a serverSide JavaScript library that was created
by Thomas Gumz with some modifications by Matt White. The original script
library is available in the XPages Discussion template which should be
on your Domino 8.5 server and the modifications can be found in the TaskJam
application which you can downloaded by going to
taskjam.net..
Many thanks to Matt for giving permission to use the modified version of
the script library. The script library will be included in the next download
of the development database.

To add the script library to our application
we open the content_Location custom control and then in the outline view
on the left of your screen select the custom control node and look at the
‘Resources’ properties tab. Click the button to add a Script Library and
then select the library from the dialog box that appears.

A picture named M2

Remain in the properties for the custom
control and go to the ‘All properties’ tab and find the ‘BeforePageLoad’
property. In here we are going to write some server side javascript code
that uses the script library. Here’s the code :



var cgi = new CGIVariables();
var param = cgi.getURLParam("Location");
if (param) {
if (param != "" )
sessionScope.locationfilter = param;
}

What this code does is before the page
has loaded it looks at the URL and finds the location= part and if it exists
it puts whatever the value is into a sessionscope variable called ‘locationfilter’.
Session Scope is a special scope where you can add variables that only
last for the duration of the users session. As soon as they close their
web browser the session scope variables are lost. There is also an Application
Scope and a Page Scope that you can use to store these values. Heres how
the code will look in the source view of your xpage, you can see the resource
for the server side script library and the beforePageLoad script. As you
get more advanced in XPages you may find yourself writing code directly
in the source view.

A picture named M3

So now we have the location taken from
the URL and stored in a sessionScope variable we need to tell the data
source to only return the values in that category. To do this we need to
look at the ‘All Properties’ tab for the custom control and look at the
‘Data’ section and expand it out to find the data source that we created
for the custom control. In here we’ll find a property called ‘categoryFilter’.

A picture named M4

In here we can reference the sessionScope
variable by clicking on the blue diamond and selecting compute value and
then entering ‘sessionscope.locationfilter’ into the script dialog box.
Our XPage source will now have an extra line up in the data source definition
:

A picture named M5

Save the custom control and then in
your web browser add a ?Location=Pittsburgh ( or whatever location you
might have in your sample data ) and load the page.

Here is my ?location=Chicago result

A picture named M6

and my ?location=Pittsburgh result

A picture named M7

You will notice how the alternating
row styles are now appearing correctly.

Now that we have a page to display,
in the next part we’ll link the sidebar to this page and then I’ll update
the downloadable database for you all to work with.

Tagged with: , , , , ,
Posted in None
Archives