I think I have my view rendering problem licked. To recap, I've been working on a way to show views in XPages that met a couple requirements:
- Entirely dynamic. Since this will be for a combined reporting site that will show views from customized project databases of wildly varying needs, I couldn't make any assumptions about view layout, categorization, or content. It should pull as much display information from the view design as possible.
- Fast. Some of these views have thousands of rows, so it should be as fast as possible to load from the database and render for the browser.
- Pagination. Though I don't really like pagination for the average case (who wants to look at a 40-row view 30 rows at a time?), sending thousands of table rows to a browser causes a miserable experience even when that browser isn't IE.
- Full-text searching and other Domino goodies. I don't want it to be a pain to just be able to search through a view like you would in the Notes client.
- Support for "second tier" Domino view features. I use special text, column hide-when formulas, "show values in this column as links", Notes-style [<span>pass-through-HTML<span>], and color columns constantly.
Of these, 1 and 5 are the most important.
I originally wrote my own code to generate a big HTML blob for the view, which was perfect on points 1 and 5 (and looked great, since I converted categories to OneUI sections), but wasn't as hot on the other points. The Extension Library's
I considered changing my custom HTML code to instead create a bunch of Java objects to make pagination easier, but performance would be an issue - it's tough to beat built-in controls for raw speed. As anyone who has looked at the code for the mail template knows, IBM/Lotus cheats like crazy, and often the only thing you can do is to just go with what they've done and beat it into shape. Thus, the answer came to me: customizer beans for the ExtLib's dynamic view panel.
The dynamic view panel has a "customizerBean" property that takes a string class name of a bean to create to hook into a couple overridable methods and events:
ViewFactory getViewFactory() - this lets you override how the panel pulls in all of its information about the view.
boolean createColumns(FacesContext context, UIDynamicViewPanel panel, ViewFactory f) - this lets you override how the panel uses the gathered view information to generate the list of data table columns (or simply run code before that happens, if it returns false)
IControl createColumn(FacesContext context, UIDynamicViewPanel panel, int index, ColumnDef colDef) - similarly, this lets you change the way each individual column is created based on the ColumnDef (an object generated by your ViewFactory)
afterCreateColumn(FacesContext context, int index, ColumnDef colDef, IControl column) - this is an event fired after each column is generated, allowing you to customize the generated column without having to build it from scratch
afterCreateColumns(FacesContext context, UIDynamicPanel panel) - similarly, this lets you run code after the column creation is done
These events provided just the hooks I needed to get the dynamic panel to do what I wanted.
To add special text support, I added an implementation of
afterCreateColumn(...) that replaced the column's default
ViewColumnConverter with my own subclass that overrides
getValueAsString(...). With that, I can walk up the current component's ancestors to find the panel, find the individual ViewEntry's variable name from there, and use that to process the special text properly.
Column Hide-When Formulas
These are a bit trickier. The
getViewFactory() hook lets me provide my own subclass of
DefaultViewFactory, but there's a reason that the dynamic view panel doesn't support these formulas by default: they're not exposed by the NotesViewColumn class. The two ways I can think of to get at this information are the C API (or otherwise reading the design information from the view note directly) and DXL. The former is no doubt significantly faster, but DXL is much, much easier and is good enough for my needs at the moment. So I export the view as DXL and process its
column nodes and their children. Then, for each with a hide-when formula, I
evaluate the formula in the context of a new document in the project's database and use the result to set the column-hidden flag.
"Show values in this column as links"
This goes hand-in-hand with the hide-when formulas. The
column nodes in the DXL have a
showaslinks attribute that I can look for to set this flag.
Much like special text, once I have the custom converter attached to the column, I can break apart and reassemble text values on
>] and XML-encode the non-HTML bits. While I'm attaching the converter, I set the column's content type to "html", since I'll be handling the encoding.
These are... tricky, and I'm not yet proud of my fix. There are two problems: getting each cell to know about its color information from previous cells and then actually applying that color information.
For the former problem, I dealt with it by adding an "activeColorColumn" property to the
ColumnDef object and setting it to the programmatic name of the most recent color column before each column.
The latter is the ugly part. You can't just set the column's style, since that will apply to the entire column and make a fine mess of everything. What you really want to do is assign it to the current
<td> element, but I don't know a good way to do that. In the mean time, I've hacked around it by making a hidden
<div> in each cell with the style tucked into a
divs and apply their styling to the parent table cell. It's not pretty, but it works for now.
If I get that last bit of code cleaned up to a point where I'm comfortable letting people see it, I'll post my example code. In the mean time, I'll count this whole thing as a win for only writing the code you need to and letting the platform take care of the rest.