Reg Exp
Web Design
Notes Client
Custom No Documents Found Message
For a recent customer, we were using quite a few views on the web, and there was one view template for all the views. With a couple of the views there was a chance for the view to be empty, which leads to the standard No documents found Domino message. This customer wanted to customize this message. Luckily, the site was for an intranet and all their employees used IE, so the solution was quite a bit easier than what we've done in the past.

In the past, we had to hide the HTML that Domino generated, have a flag that says there are no documents, then have some JavaScript to generate our own message if the flag is set. That involves updating the view to stop hiding the HTML that Domino generates (when there are documents) and clear the flag so our own message won't be generated. With this solution, you just need to update the template. We enhanced the solution to default to the standard Domino way if the browser isn't IE.

First, don't make any changes to your view (or "views" in our case, which made this solution more attractive). Just go into the view template. Before the $$ViewBody field, add one line of pass-through HTML:
<div id="ViewBody" style="display:block; visibility:visibile;">

This will put the entire view HTML that Domino generates into its own division, which can be hidden later programmatically if there are no documents in the view. After the $$ViewBody field (which should not be in pass-through HTML), close out that division with a <div> tag.

Next, add a division that will appear if there are no documents. The division will be hidden initially and shown later if needed. To handle Netscape 4, put the division in a hidden layer. This will cause Netscape 4 to use the standard Domino message. Here's the pass-through HTML you will need:

<layer id="NoDocumentsFoundParent" style="display:none;">
<div id="NoDocumentsFound" style="display:block; visibility:hidden;">
<h1>Hey, there aren't any documents in this view!</h1>

Obviously, you can put whatever message you want inside the division.

Next comes some JavaScript to programmatically hide the Domino-generated view and show the custom "No Documents Found" message if needed. The JavaScript can appear right on the page so it will run in-line while the page is being generated. It must appear after both the "ViewBody" and the "NoDocumentsFound" divisions, however. Here is the JavaScript:

<script language="JavaScript" type="text/javascript"><!--
   if ( (document.getElementById) && (document.getElementsByTagName) ) {
      var tags = document.getElementById("ViewBody").document.getElementsByTagName("tr");
   } else if (document.all) {
      var tags = document.all["ViewBody"].document.all.tags("tr");
   } else {   // Unknown - don't use the "No Documents Found" division
      var tags = new Array("x");
   if (tags.length == 0) {
      if (document.getElementById) {
         document.getElementById("ViewBody").style.visibility = "hidden";
         document.getElementById("NoDocumentsFound").style.visibility = "visible";
      } else if (document.all) {
         document.all["ViewBody"].style.visibility = "hidden";
         document.all["NoDocumentsFound"].style.visibility = "visible";
//   -->

For IE 5 and later, the functions "getElementById" and "getElementsByTagName" are available. So the first "if" block is used. Check to see if there are any "tr" tags within the "ViewBody" element. If there are, then the tags variable will have some kind of an array. There will only be "tr" tags if Domino generated a table because there were documents in the view. If there were no documents, then there won't be any "tr" tags generated by Domino. A similar method is used for IE 4 in the second "if" block.

For all other non-IE browsers, set up the tags array to have a length of 1. This will mean the next large block won't execute and whatever Domino generated will be used.

If there were no "tr" tags (which could only be the case if the browser is IE 4+ and there were no documents), then hide the "ViewBody" division and show the "NoDocumentsFound" division. This is pretty standard code for showing/hiding divisions by getting a handle to the division, then modifying the "style.visibility" property.