In traditional domino web development when
you add a view to a webpage and there are no documents you would end up
with a standard ‘No Documents Found’ message. In many cases as a developer
you would would then apply a number of hacks to either replace or control the look and feel
of this message.
In XPages we now have the concept of
view panels or repeats to list all the documents in a view and for the
most time you will use these types of controls with a pager control to
allow the user of your application to go back and forth through different
pages in the view. This is a vast improvement on traditional domino
web development but it does bring up one new issue, what if the view has
no documents, do you even want the pager to display? In the phonebook
application I created for the Learning XPages series my pager had a ‘Page
1 of x’ section, on a view with no documents that appears as ‘Page 1 of
0’ which is just wrong so I wanted to hide the pager and instead display
a friendly message to the user.
To hide the pager I needed to set it’s
rendered’ property to a computed value. I decided to look at the row count
for the repeat that I was using on the page and check to see if it was
zero. If it was zero then I would hide the page and if not then I would
show the pager. I decided to use the row count for the repeat control instead
of the row count for the data source because if you are using filters on
the data source then the row count for the repeat control is the number
of rows AFTER the filter is applied whereas the row count for the data
source is the number of rows BEFORE the filter is applied.
Here’s the code that I used for the
pagers render script in a simplified/expanded form :
var testValue
= getComponent("itemListRepeat");
if (testValue.getRowCount() == 0 ){
return false;
} else{
return true;
}
If you want to create a customized message
to display to the end user you can simply create a new panel control that
contains your message and apply the exact same rendered formula expect
switch the true and false statements. You can also apply a special styleclass
to the new panel to help make it stand out. If your using the oneUI you
could use ‘lotusMessage’ to make it look like this :
One interesting thing that I found is
that you can hide the panel containing the repeat control using the exact
same formula. Even though the repeat control is inside the panel that your
hiding it’s row count is available to check before the page is rendered.
I’m not sure if this is intentional or not so if you do hide the entire
repeat panel as well any pagers linked the repeat make sure you test this
in future versions.
Nice one. There is also an important insight inside (pun intended):A repeat control will execute its data acquisition code even if you will not render it. So unless you need information from it (like the example here) you might want to incorporate your hiding condition into your repeat code, so you don’t lookup things you don’t display or need. stw
LikeLike
Just a little heads up, Dec … This post is tagged with “xpage”, not with “xpageS” as the other xpages posts are. Is that on purpose?
LikeLike