Learning XPages Part 25 : Scripted Linking Between XPages

In the last part I showed you how you can
create a simple action on the onClick event to link the single location
list to the person XPage. In this part I’m going to write a serverside
script instead of using the simple actions however before you decide this
is the right way to do your linking there is one important caveat  that
you need to know before doing it this way….

Here’s what the URL looks like right
now for a document

A picture named M2

You can see in the URL that the action
and the document ID are part of the URL. If you bookmark this URL and then
look at the bookmark at a later date then the link will work perfectly.
With the method I’m about to show you I’m going to be using the sessionScope
to store some values, these values disappear once the user closes their
web browser and the URL will only say Person.xsp so a bookmark won’t work
so if you care about bookmarks then you need to make sure the values are
part of the URL.

Lets open the content_Location custom
control again and find our <xp:tr> tag that’s inside the repeat control.
We are going to look at the events tab again and select the ‘onClick’ event
but this time we will use the ‘Script Editor’ instead of simple actions.

A picture named M3

Because we already had a simple action
in there it will ask if we are sure because changing from one to the other
will wipe out any code or actions you have created. Go ahead and click
OK and you’ll see the script entry box. Here’s teh script I’m using :

sessionScope.personDocID = rowData.getUniversalID();

The first line sets the sessionScope
variable called ‘personDocID’ to the UNID of the document that has been
selected. The second line instructs the browser to open the ‘Person’ XPage.
If we save and preview our XPage right now it will fail because we have
not told the person XPage how to use the session scope variable. so just
save and close the content_Location custom control for now and open up
the content_Person custom control.

When we first defined the data source
for the content_person custom control we did not specify a document ID.
Go back to the data properties for the control and select the blue diamond
beside the ‘Document ID’ part of the data source and select the ‘compute
value’ option. The script entry dialog box will appear and in here we add
the reference to our session Scope variable like this :

A picture named M4

Now we can save our content_Person custom
control and refresh our Xpage in the browser. Select a person from the
location list and it should open up the person XPage for that person and
while the document opens up to the correct person the URL bar will not
contain any extra parameters

A picture named M5

Congratulations. You now have the the
basic phonebook application completed. You can view the list of locations,
click a location to get a list of the people in that location and then
click on a person in the table to get to the details about that person
however we still have a few more things to do to make our application easier
like make the person details screen look nicer, write some client side
javascript to change the background color of the rows in the list of people
so the user know which one they are hovering over and we also need to do
something with our PlaceBar which has remained untouched till now. All
this and more will be covered in the remainder of the series.

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