Reg Exp
Web Design
Notes Client
Open Dynamic View Panel Documents in Read Mode
I really like the Dynamic View Panel (<xe:dynamicViewPanel>) control from the XPages Extension Library. It allows you to quickly include a bunch of views in your application. Just compute the Domino View inside the View Panel to be the view you want to display. You don't get the control that you can get with a Data View or a View Panel, but it's also way faster to implement. But the links to the documents open the documents in edit mode.

For the application I was working on, I wanted the documents to open in read mode instead of edit mode. I found a couple of posts on the frostillic.us web site (here and here) that talk about extending the control and adding your own functionality. Although that is really cool, it was a bit of overkill for a couple reasons. First, it will take a while to implement that (once you do it once, the second time will be easier, but I was guessing that I'd spend several hours getting it working and I'm on a time budget for this project - don't need to spend any more time that I have to). Second, I'm not going to be the one supporting this application when it's finished. I'm already pressing my luck by including jQuery, and including a bunch a Java is over the top. Third, all I wanted to do was change the document to open in read mode instead of edit mode - nothing too complex.

It turns out that it was pretty easy to implement.

First, inside the dynamicViewPanel control, add an "onClientLoad" handler. If it's inside the dynamicViewPanel, it will run every time the view changes or anything about the view changes (expanding a category, doing "expand/collapse all", etc.). The code simply calls a JavaScript function that we'll define next:

<xp:eventHandler event="onClientLoad" submit="false">

Next, add a script block that will call a jQuery function to change all the "editDocument" to "openDocument". The jQuery selects all links that have "documentId" in them (documents being opened) and changes the href property.

<xp:scriptBlock id="scriptBlock2">
    <xp:this.value><![CDATA[function fixLinks(){
            this.href = this.href.replace('editDocument','openDocument');

So, every time the Dynamic View Panel is used or something changes in the Dynamic View Panel (like expanding or collapsing) then all the links that open documents will have their links changed to use "openDocument" instead of "editDocument", which will open the documents in read mode.