logo

Domino View Navigation a la Web

I'm working on converting an IIS/Flash website to Domino at the moment. The new Domino site has to work as near to exactly the same as the .asp site as possible. I'm determined to eradicate all the Domino nuances. This morning I excised it of an age-old view navigation gotcha, using some simple LotusScript.

Have a look at the gallery on the current site. Click on an artist to launch the popup with a photo in it. Notice this popup has previous and next links. Easy to do in Domino with a simple @Command([NavigateNext]) Action Hotspot. The trouble is that Domino throws you back in to the view when you press next and happen to be in the last document. I needed to replicate the way that the previous link didn't appear in the first document and, similarly, neither did the next link in the last.

To do this I created a field on the popup document call "Position". Its value will be set to either "First" or "Last" by a WebQueryOpen agent. Using Hide When Formulas it's easy to hide the links when they don't apply.

The code for the agent is quite simple (I've missed out the Dim statement for the sake of brevity):

Set doc = session.DocumentContext
Set view = db.GetView("gallery")
Set nav = view.CreateViewNav()

Set ThisEntry = nav.GetEntry( doc )

Set FirstEntry = nav.GetFirstDocument
Set LastEntry = nav.GetLastDocument

If ThisEntry.UniversalID=FirstEntry.UniversalID Then
 Call doc.ReplaceItemValue( "Position", "First")

If ThisEntry.UniversalID=LastEntry.UniversalID Then
 Call doc.ReplaceItemValue( "Position", "Last")

It uses the NotesViewNavigator class that was new back with R5. Don't know why I've not thought of doing this before. Have I re-invented someone else's wheel?

Using the Count property you can also hide previous/next links at the view level and even add some "Page X of Y" text using a WebQueryOpen agent in the $$ViewTemplate.

Does that make sense? Is it too obvious/simple for me to bother making an article of it with a demo DB?

Note: Since I wrote this I found a small logic problem with the code. Can anybody spot it?

Comments

  1. Articles are great, even if they are simple. So go, Jake!

    • avatar
    • Caroline
    • Wed 3 Nov 2004 07:37

    I guess you're not catering for there only being one doc...

    • avatar
    • Jake
    • Wed 3 Nov 2004 07:43

    Well done Caz. I changed the code to:

    If ThisEntry.UniversalID = FirstEntry.UniversalID Then

    Call doc.ReplaceItemValue( "IsFirst", 1)

    IsFirst and IsLast fields are Number type, default 0. THe hide when is then simple IsFirst for the previous link and IsLast for next.

  2. Any reasons for not using the following two methods: notesViewNavigator.GetPrevDocument and

    notesViewNavigator.GetNextDocument?

    - You will only have to test if either method returns nothing ..

    • avatar
    • Jake
    • Wed 3 Nov 2004 08:20

    Only that I didn't think of it Richard. You big show-off!

    As with all cats they can be skinned in many ways.

  3. >:)

  4. What about using the "?Navigate&To=Next" (or "Prev") URL commands? I didn't test what would happen at the end of the document, but much cleaner than script (IMHO).

    In case you're wondering what I mean: {Link}

    I'll have to test it out to settle my own curiosity... but if you get the chance... ;-)

    -Chris

    • avatar
    • Jake
    • Wed 3 Nov 2004 14:37

    Chris. Something I'll mention more tomorrow (maybe Friday) is the Google friendliness of Domino links. I'm not sure how &navigate=next figures in this rank.

    Plus, this feature has the same undesired effect of dumping you in to the view when there's no document to move to. And a user should NOT see this link if it's of no use!

  5. Jake, When do we get to see the completed app so that you may gloat about the size of your enormous cranium and your Domino Development prowess?

    • avatar
    • Jake
    • Wed 3 Nov 2004 15:39

    Which app Joel? The website or my demo db? Either way, probably within a week or two.

    I do actually have a really large head. I remember when I joined Scouts that had to order my hat in especially ;-)

    • avatar
    • Matt
    • Wed 3 Nov 2004 21:19

    Did something very similar on a recent project. Some people within the organization were still using the 4.5 client; an embedded view wasn't an option. The only choice was to create a form that had Next/Previous buttons, marching through a NotesDocumentCollection.

    One caution...I seem to remember that the NotesViewNavigator class wasn't all that "performance friendly" back in the R5 days. I'm not sure if that's still the case in ND6.

    • avatar
    • laurens
    • Thu 4 Nov 2004 02:19

    I precalculated the Next button as a field in a PostSave on all Pictures in a certain category. Calculating at saving has to be done only once. Calculating at viewing has to be done at each viewing.

    Code you might use to skin the cat:

    all_docids_in_category:=@DbLookup("";"":"";"Pictures"; Category;3);

    elements_in_list:=@Elements(all_docids_in_category);

    element_in_list:=@Member(DocID;all_docids_in_category);

    MIDREFS:="0/"+@Subset(@Subset(all_docids_in_category;-(elements_in_list-element_in_list));1) +"?opendocument";

    ENDREF:="Home?openform";

    @If(elementinlist=elementsinlist;ENDREF;MIDREFS)

    This code takes the DocId of the next document in the view to calculate an a href link. If it is the last document in the category, it returns to the home page. A recalculate all is done on Save.

    • avatar
    • Richard
    • Thu 4 Nov 2004 03:23

    Laurens,

    One of the problems I can see with using your code is that if somebody decided to change the order of the documents in the view or add another document that goes right into the middle of the view, the user would have to remember to refresh all the documents - this is not something the average office idiot would remember or want to do!

    Because the code is in the PostSave event section on the form, making calls to the following functions : "@Command([ToolsRefreshSelectedDocs])" and "@Command([ToolsRefreshAllDocs])" would <em>not</em> cause the code in the PostSave event or any other event to be executed ... :-(

    • avatar
    • Paul
    • Tue 9 Nov 2004 11:15

    Laurens,

    Your code is great however, unless things have changed in R6, you will run into the 64K limitation with @DbLookups if your category contains more than 2000 documents (64K/32bytes = ~2000).

    Jake,

    You asked what the logic error was in your code... Your If statements should read:

    If ThisEntry.Document.UniversalID=FirstEntry.Document.UniversalID Then

    Same for the second if statement. In order to access the UniversalID of the document you must first reference the document contained by the entry that you have retrieved.

    I did want to thank you Jake as I was having trouble creating a navigation structure similar to this but via different means. My documents open in a completely different window and I was trying to use the NotesViewNavigator class to retrieve the entry represented by the open document. The navigator was created just fine, but because I was calling an agent instead of a document my doc in s.DocumentContext referred to the agent and not the document I was working with and entry was not being set. Responding to this post helped my figure this out. OK I am now wearing the pointy Dunce hat and sitting in the corner... ;-)

    • avatar
    • Jake
    • Wed 10 Nov 2004 10:27

    I don't like to be picky Paul, but, that wouldn't really be a logic error as such, and it's not an error anyway. You can get the UNID using this property of the ViewEntry, without needing to get a handle on the document.

    • avatar
    • Paul
    • Wed 10 Nov 2004 15:30

    Thanks Jake. I noticed that as soon as I submitted the post. My bad. ;-)

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Wed 3 Nov 2004

Share This Page

# ( ) '

Comments

The most recent comments added:

  • avatar Paul about 19 years ago
  • avatar Jake about 19 years ago
  • avatar Paul about 19 years ago
  • avatar Richard about 19 years ago
  • avatar laurens about 19 years ago
  • avatar Matt about 19 years ago

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content